How to create a different second level block for every menu link? I'm creating a small project and got stuck on the following:

Im using the module Menu_block to create my navigation menu second level.
What i need is a different background for each second level. (Not every link needs a different background, but the compleet block.)
Menu_block creates one block for all the second level items.

Now is there a way to make the one block into seven (i got seven menu links) blocks or is there an other way i could do this?

For a layout of the website see the following link: https://www.dropbox.com/s/p5nr0zm3r2eatbw/layout%20website.PNG
The number 1 or 2 background is what I want to change according to the current active navigatie level 1 link.

Different colour second level menu items

I would not use a block for each menu item even if you could.

The menu items should have classes with their mlid (menu link id), which is unique to the menu item.

You can add different colours with css based on those classes.

Different colour second level menus based on active path

Now that I understand your question you want the whole second level menu block to be coloured based on the currently active top level menu item.

In this scenario I think it is more acceptable to have a second level menu block for each parent menu item, so that is one solution, in which case you can easily style the blocks differently as they have different block IDs.

An alternative solution, is to add a single second level menu block for your main menu, and then add this code to your theme's template.php file:

/**
 * Override or insert variables into the menu block wrapper template.
 */
function THEME_NAME_preprocess_menu_block_wrapper(&$variables) {
  $active_trail = menu_get_active_trail();
  foreach ($active_trail as $item) {
    if ((!(bool) ($item['type'] & MENU_IS_LOCAL_TASK)) && !empty($item['mlid'])) {
      $variables['classes_array'][] = 'active-top-level-mlid-' . $item['mlid'];
      break;
    }
  }
}

That code will add a class to the block like active-top-level-mlid-405 - where 405 is the mlid of the active top level menu item.

You can then theme the block using this class.


Wrong value when using PHP with the Views module I have a float field, and I just want to print this field in a PHP field. I am using this code.

print $row->title; // It prints the same value.
print $row->field_pa_total; // It prints the wrong value; the field value is 5000, but the printed value is 40.

How do I print the field value?

print_r($row); should give you the structure of the row and tell you the names of the various fields and values etc.


Not able to update module via drush I am trying to update a module via drush. Referring this link

[root@localhost d7]# drush update
The drush command 'update' could not be found.  Run `drush cache-clear drush` to clear the commandfile cache if you have    [error]
installed new extensions.

But it is giving error that 'update' command could not be found. Can anybody help me with this?

Update all update available modules other than locked modules.

drush pm-update

or

Update specified module only.

drush up 'module-name'


Use image from view as background image of div in page.tpl.php I need to use the image resulting from a view as the background image to a div in my page.tpl.php.

I am able to render the page title with the view below it using:

    <?php print $title ?>

  <?php $views = views_embed_view('photos', 'block'); print render($views);?>

However, is there a way that I can pull the image from the view, and use it as the background image for container-inner?

Sure.  Just look at what's inside $views and grab the path/url of the image there and stuff that into $background_image and then do something like:

<div class="container-inner clearfix" style="background: url(<?php print $background_image; ?>)">

Sidenote:  it might be better to this in a preprocess hook and pass in this as a variable instead of putting this logic in your page.tpl.php file, eg, something like:

function my_module_or_theme_preprocess_page(&$vars) {

  // $views=views_embed_view('photos', 'block');
  $views=views_get_view_result('photo', 'block'); // appears to work easier :)
  $background_image=// however you get the url/path to the image from $views;

  $vars['background_image']=$background_image;

}

which will create a $background_image variable that is now available inside page.tpl.php.


View by Taxonomy terms hide empty terms unless they have children I am trying to get my views block to display terms under this parent term but only show the terms with nodes in them. I managed to get this to work by using the relationship content with term and requiring the relationship. However we have terms with children that are empty but the children are not empty. I want it to display the term(without showing the children)

How do I make my views block display terms under parent term, remove the empty terms but show the empty terms with children?

Your friend is:

  Taxonomy term: Representative node

This is a  duplicate, by the way.


Add a field to multiple content types at once? I want to add a field to multiple content types at once, and configure it for all of them at once as well.

Reason being is that I have many content types, all of which need to be updated by adding this new field to each.  This field will be configured the same for all of the content types as well.  I have to repeat this process of adding and then configuring the field every content type I want to add it to, and it gets arduous after a while.

Is there any way to do a mass add/configure of a new field to many content types?

Broad lines using the Features module could be:

Add the field to two (to see the pattern) content types by hand
Create a Feature including field bases and field instances for the newly created fields
Edit the created module multiplying the field bases and instances to all content types needed
Enable the edited module


How to override a single function in a core javascript library? Drupal 8's core comments module has a library "node-new-comments-link" with a file "node-new-comments-link.js".

This contains Drupal.behaviors.nodeNewCommentsLink = { ... } which calls another function in the library which in turn calls another function in the library function render(results) { ... }.

This render function controls the text used to show how many new comments a node has:
.text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments'))

I want to use different text. (I want it just to say 'New' rather than 'x new comments').

I can replace the whole js file or the whole library and that works fine, but it's very heavy handed. It requires me to copy paste lots of complex code I don't need to understand.

Is there a way to override just this one render function?

You can enable interface translation for English in /admin/config/regional/language/edit/en

[x] Enable interface translation to English

and then you are able to change the string you are looking for in User Interface Translation.


Checkbox to make billing information same as shipping information does not work for Anonymous users For Anonymous users, the My Shipping information is the same as my Billing information checkbox doesn't reload the Shipping Information checkout pane.

I have the checkbox working for authenticated users, but when an anonymous user is going through checkout, the ajax callback never fires. The #element_validate function 'commerce_customer_profile_copy_validate' is never called. The #ajax['callback'] => 'commerce_customer_profile_copy_refresh' is never called.

Watching the network tab in Chrome, the ajax request is never fired.

The checkbox is checked by default and nothing happens when I un-check it. The Shipping Information pane doesn't expand and show the shipping information form fields via ajax.

Is there some permission I'm missing that would allow anonymous users to use this checkbox?

Turns out I was kicking myself on this one. I forgot I had some custom hook_js_alter code in my template.php that removes unnecessary js from the page for anonymous users. This was done to improve site speed and because my custom theme didn't require these default Drupal js libraries.

function theme_js_alter(&$javascript) {
  $logged_in_user = user_uid_optional_load();
  if(!in_array("authenticated user", $logged_in_user->roles)) {
    foreach($javascript as $key => $value) {
      unset($javascript[$key]);
    }
  }
}

However I do need these javascripts on commerce checkout pages apparently, so I added a request_path() check for checkout and cart pages so the js would not be unset.

I confirmed the My Shipping information is the same as my Billing information checkbox now works for anonymous users.


RuntimeException: Unable to determine class for field type found in the configuration My website got this error, while updating from Drupal 8.3.7 to Drupal 8.4.0, and I am unable to solve it.

  The website encountered an unexpected error. Please try again later.
  RuntimeException: Unable to determine class for field type 'webform' found in the 'field.storage.node.webform' configuration in Drupal\field\FieldStorageConfigStorage->mapFromStorageRecords() (line 157 of core/modules/field/src/FieldStorageConfigStorage.php).

One possible way is that your module is missing from the codebase or has been improperly uninstalled and you've still a field which is using that missing module.

Try the following drush/SQL commands to remove the broken field:

drush sqlq "DELETE FROM cache_config"
drush sqlq "DELETE FROM config WHERE name = 'field.storage.xxx.xxx' OR data LIKE '%field.storage.xxx.xxx%'"
drush sqlq "DELETE FROM config_snapshot  WHERE name = 'field.storage.xxx.xxx' OR data LIKE '%field.storage.xxx.xxx%'"

Warning: Don't execute above commands on master/live database. Make a backup before doing any database changes.

Where field.storage.xxx.xxx is your reported field storage type (e.g. field.storage.node.webform).

If above won't help, check for any other references by:

drush sql-dump --ordered-dump | grep field.storage.xxx.xxx

At the end you need to rebuild your caches:

drush cr


Disable path user on Drupal 7 Since most of my d7 users will authenticate somewhere outside Drupal itself, I need to disable "/user" path for most of them (not uid 0 of course).
What is the best approach we have here?

how about

function mymenu_menu_alter(&$items) {
$global $user;
 if ($user->uid != '0'){
  $items['user']['access callback'] = FALSE;
}
}


Options for "create and reference" In a screencast based on Drupal 6, I spotted (~3:45) that several fields had an additional "create and reference" icon that would pop a secondary dialog, for in-place creation of non-existent nodes, which would then be added as reference. This appears to be missing from Drupal 7 Reference module, which is now responsible for fields of that type, and I can't seem to find any evidence it's going to be put back.

My homework:
I dug up an old groups.drupal thread where eventually someone posted a round-up of many options last year, but most of those now range from inactive to abandoned. A few have issue threads full of people asking about a Drupal 7 upgrade, with absolute silence from the maintainers.
From that list, two actually show Drupal 7 work:

Node Reference Create: Seems to only do the barest minimum: create a node with a title of what you input in the textarea. To provide values for any other fields, you need to make your way over to that node's individual edit screen. This isn't enough for my needs.
Corresponding node references: I'm actually just not sure why this is even on the list. I've installed it, poked around, and can't actually find this feature implemented. Am I just missing it?

I'm also aware of Relation, which seems intended to supersede just about every other reference-ish module and I presume will do this. But it doesn't even have any released code at the moment, and this research is for something I'm working on right now, timeline of probably a couple months tops.

Are there any currently viable options for accomplishing this? I'm willing to guinea pig anything at least in beta status. Or do I need to give serious consideration to doing this in Drupal 6 instead?

If you are using the overlay module in Drupal 7. Create the main node but use the Node Reference URL widget on the referencing nodes. This will put links on every node view page that behave similar to the Relationships module. If you add Field Collections module to group all the fields, you can get edit in place with overlay popups on the node.

The workflow would be like this. 1. Create a node. 2. The node form only asks for the title of the node. 3. Return to the node with several different parts, each getting their own popup form or if JavaScript is enabled a return destination back to the node after creating or editing.


Drupal commerce: product field based in calculation of other fields The commerce product has the field: Price

Then I added two more field: Quantity and Price per Unit

I need the field Price per Unit to take the calculated value from this:

Price per Unit = Price/Quantity

How I get this?

Commerce out of the box has a quantity field and does by default a 'price-per-unit'. Watch this tutorial to give you an idea of how it works without any customizations.

https://www.youtube.com/watch?v=3KEJcieG4jI


System pager isn't showing for logged in users I'm using Panels 7.x-3.2 on Drupal 7.12. I have the Panels Taxonomy term template enabled and for some reason, there's no pager being rendered below the content. You can manually append ?page=x to the URL and it works, but the pager isn't being shown.

It displays if I enable the Taxonomy Term View instead of the Panel, but I need to use Panels to handle term output in order to heavily customise the layout of terms under a specific vocabulary, so using Views for it isn't really an option.

Any ideas? I looked through the Panels settings both for the specific Panel page and the general ones, but there's no mention of pagers or pagination anywhere, so I'm completely stumped...!

EDIT
turns out this isn't Panels related. D'oh. It appears to be strictly related to Taxonomy itself. I recall having this issue before, where a Taxonomy term page should have shown a pager but didn't until I overrode the output using Views' Taxonomy term page. Not sure what's causing this but I can't find any related issues for Drupal 7.x core, so maybe it's something to do with my theme (which is derived from Zen)?

EDIT 2 (25-Apr-12)
after extensive scouring for the cause of this problem I have been able to narrow it down further, but not much. Here's what I know at this point:

It's affecting system-generated (non-Views) Taxonomy term pages
The pager is rendered to anonymous users; as soon as you log in, regardless of the account/roles/permissions, the pager disappears
Pagination itself works; you can append the ?page= parameter to the URL and it will return the specified page of content
Changing the theme to Bartik fixes the problem

Given that, you'd think my themes (I'm using a parent one and a child theme, both derived from Zen) doing some really weird stuff with page output, but there's absolutely nothing in them that could logically affect paging - especially not for logged in users. In fact, the only hooks they implement are:

template_preprocess_page() (to add some page-specific JS and CSS)
hook_form_alter() (to customise the search form)
hook_privatemsg_message_presave_alter()
theme_breadcrumb() (pretty much as written in Zen)
theme_menu_local_tasks() (also pretty much as written in Zen, which in itself is almost like the original code for it - tweaks the HTML for tabs slightly)
theme_menu_local_task() (again, just the Zen implementation)
template_preprocess_html() (to add body classes)
template_process_page() (very small if condition to specify if the page is a node or not)

Plus some other process_ and preprocess_ hook implementations to add some classes and tpl suggestions. There's absolutely no manipulation of any "pager" stuff anywhere, or nothing obvious anyway... so this has really stumped me, but it has to be something in my themes surely?

Also, just to clarify, it's definitely not a case of CSS interference as the markup doesn't even make it into the output - it's completely absent. Argh!

Finally figured out the problem with some help from a friend. It was being caused by a conflicting pager in a custom made View that rendered the current user's picture in a block on every page. It's only set to display when the user is logged in, hence why the problem was non-existent for anonymous users.

Changing the pager settings for the view from "Full, display 10 items" to "Display all items" has fixed the problem (presumably since there's only a maximum of 1 user picture to output in the View, Views dictated that there was only 1 page and that interfered with the other pager).

I suppose another solution, although not necessary in this case, would be to change the View's Pager ID.

In hindsight the solution is pretty obvious, because I have known about the Pager ID setting for a long time, and even knew what it did - but hopefully this will come in useful for anyone else with a complex site layout running into the same problem. :)


How to count the number of nodes with a certain taxonomy term, based on a list of nids? The users on my website have an integer field My medals, which can contain an unlimited amount of values, representing nids from nodes of the type Medal. Every Medal node contains one term of the taxonomy Colour (either Gold, Silver and Bronze).

Given a certain uid, I would like to create a View that shows the total number of nodes per taxonomy term, based on the user's field My medals.

Example. Suppose the nodes with nids 1, 2 and 3 have a Gold term, the node with nid 4 has a Silver term, and the node with nid 5 has a Bronze term. Let user 1 have a My medals field with values 1, 2, 4, 5. Then the View should return "Gold: 2, Silver: 1, Bronze: 1" when the uid 1 is given.

Mmm i dont think drupal 7 views is up to this perhaps this work around may help
create a custom module and put

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {
  $blocks = [];
  $blocks['my_block'] = [
    'info' => t('My Medals'),
  ];
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function mymodule_block_view($delta = '') {
  $block = array();
  switch($delta) {
    case 'my_block' :
      $block['content'] = my_block_view();
      break;
  }
  return $block;
}

function my_block_view() {
  global $user;
  $uid = $user->uid;

  $result = db_query('SELECT * FROM {node} WHERE uid = :uid AND type = :type', [
   ':uid' => $uid,
   ':type' => 'post'
  ]);
  $node_ids = [];
  foreach ($result as $row) {
    $node_ids[] = $row->nid;
  }
  $output = '';
  $gold = [];
  $silver = [];
  $bron = [];
  if (count($node_ids) != 0) {
    foreach ($node_ids as $nid) {
      $node = node_load($nid);
      $tid = $node->field_term['und'][0]['tid'];
      switch($tid) {
        case 1;
          $gold[] = $nid;
        break;
        case 2;
          $silver[] = $nid;
        break;
        case 3;
          $bron[] = $nid;
        break;
        default;
        break;
      }
    }
  }
// bad practice but quick win.
  $output = 'GOLD ' . count($gold) . ' Silver ' . count($silver) . ' Bronze ' . count($bron);
  $block = [
    '#type' => 'markup',
    '#markup' => $output,
  ];
  return $block;
}

The above will create a custom block then you have to place the block on the user and change the   "global $user; $uid"  to fit your need.


Preview option for entity registration form Is there a way to display preview before submission using Entity Registration?

Similar functionality as there is with node submit option. So that user can make changes if anything is wrong.

I have one another option that i have used:

function your_Module_name_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'your_form_id') {
       $form['submit']['#attributes'] => array('class' => array('upersubmit'),'onclick' => 'if(!confirm_vil(this.id)){return false;}');
   }

}

/* Js Function in your js file */

function confirm_vil(val){
    /* Now here you can add popup code to view all data before submit */
}

i hope this is help you..


How do I add a file upload button? I have a view and have styled the view with a Twig template. The view show nodes whose content type is Programs. I would like to add a Upload button in the view so that admininistrator users can add reports. The view structure is the following one.

Is this possible through the Drupal UI?

I created the File upload field as a file type, but it is allowing administrators to add files only through the node page.
Is there a way to make the upload button appear on the view itself?

There is a beta version of a module that can help you achieve this:

https://www.drupal.org/project/views_entity_form_field

  This module provides the ability to add form field widgets to a view to edit multiple entities at one time.

  Form field options will show up in a View's "Add field" list, prefixed with "Form field: " and then the name of the field being added.


Restrict node list in entity reference field based on node field My "Article" nodes have a "domain" field that links to a taxonomy term.
My "Article" nodes also have a repeatable "entity reference" field "more like this" that links to other "article" nodes.

How can i restrict the list in the "more like this" field to show only the nodes that have the same "taxonomy term" that the node i am currently editing ?

Thanks a lot !

For the PHP solution you have to provide an EntityReferenceSelection Plugin. I give you an example from my "proreos" project:

namespace Drupal\proreos\Plugin\EntityReferenceSelection;

use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
...

/**
 * Plugin implementation of the 'selection' entity_reference.
 *
 * @EntityReferenceSelection(
    *   id = "default:proreos",
    *   label = @Translation("proreos selection"),
    *   entity_types = {"address_entity", "anwalt_entity", "library_entity"},
    *   group = "default",
    *   weight = 1
    * )
    */
class OwnEntitiesSelection extends DefaultSelection {

  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
      $query = parent::buildEntityQuery($match, $match_operator);
      ... your code here to modify the query ...
      ... (I do $query->condition('user_id', $currentUid);) ...
      return $query;
   }}

You may also need to override validateReferenceableNewEntities().
Look for more examples in the core modules.


How to resolve my 404 error when using hook menu? I've a custom module named workingmodule. I get a 404 when  visiting domain.com/workingmodule.

My module is enabled, and I cleared the cache. This id the code I am using in workingmodule.module.

/**
* Implements hook_menu().
*/
function workingmodule_menu() {
  $items = array();
  $items['workingmodule'] = array(
    'page callback' => 'workingmodule_blank_page_callback',
    'page arguments' => array(),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
* Display the tagboard/custom content for page.
*/
function workingmodule_blank_page_callback() {
  print_r("test");
}

Why does domain.com/workingmodule return a 404 error?

I tested the code by adding that path and it works.

I suggest the following steps debug:

Make sure that Drupal is able to flush the cache without any problem by checking if there is any errors at admin/reports/dblog
If you didn't find any errors when you flushed the cache, try to add a die('checking hook_menu') on your hook_menu implementation to see if the hook is being executed.
If you are not going to pass any arguments to that callback I suggest you to remove the line 'page arguments' => array(),
Check your Apache/NGINX settings, it could contain something that is affecting that path.


Using Views as a report in a custom module I'm new-ish to module development. I just need to be pointed in the right direction.

I have a custom module that I think would benefit from a report. The report should show up in the admin reports menu. (I already know how to use hook_menu to display "Hello world!" as a report in the reports menu.)

It seems to me that the easiest way to compile the data for the report would be to use Views. But where do I go from here? How do I programatically use a View as one of the reports my module provides? (Or am I wrong in assuming that this can be done or is a good way of doing things?)

To be clear: I am not talking about my module providing a default view that shows up in the views menu, but using the data from a View as a report.

What I want is the same result as this idea, but programatically in my module.

views_get_view_result is the API you should use to query an existing View and process the results in your module.


How do I apply patch in vendor directory using composer? Background:

Drupal 8
Managing dependencies with compose

I want to apply one patch to vendor/behat/web_api_extension project.

I tried with this in composer.json but it doesn't works or no error.

"extra": {
    "enable-patching": true,
    "patches": {
        "drupal/better_formats": {
           "Settings have no affect on the field if it is in a Paragraph bundle - https://www.drupal.org/node/2754029": "https://www.drupal.org/files/issues/better_formats_paragraphs-2754029-15.patch"
        },
        "vendor/behat/web-api-extension": {
            "behat web api definition conflicts with mink extensions": "patches/behat_web_api/alter-definitions-text.patch"
        }
    }
}

You will need cweagans vendor to make composer able to parse the extra->patches lines.

This line is wrong I think: "vendor/behat/web-api-extension"
You always need the package name (without version) and not the relative path.
In your case it should be "behat/behat"


Is it possible to redirect anonymous users from /admin to /user? Say I have a site called drupal.local, the user login page would be drupal.local/user. And the admin 'homepage' would be drupal.local/admin.

The problem is that lots of people seem to expect drupal.local/admin to lead them to the login page if they are not already logged in. Unfortunately instead of doing that, they just get:

  You are not authorized to access this page.

I guess (thinking about it) a decent solution would be to put a link to the login page in the 403 error template text - but it would be more elegant to redirect the user to /user if they weren't already logged in.

Is it possible to do such a thing?

Sure, you can install a module like Redirect 403 to User Login:

Redirect the HTTP 403 error page to the Drupal /user/login page with an optional message that reads:

"Access denied! You must login to view this page."

Also, the desired page is appended in the url query string so that, once login is successful, the user is taken directly where they were originally trying to go.


Get node_type entity for default value in form I'm attempting to allow users to enter a number of node types in an entity reference field inside a custom config form. However I can't seem to supply it with a proper default value. My field in the form looks like this:

$config = $this->config('contentform.settings');
    $form['content_types'] = [
        '#type'          => 'entity_autocomplete',
        '#description'   => t('Choose what content types to map'),
        '#target_type'   => 'node_type',
        '#default_value' => $config->get('content_type'),
    ];

However $config->get('content_type') only supplies me with the label of the content type.

So I get the following error

  InvalidArgumentException: The #default_value property has to be an
  entity object or an array of entity objects

I'm saving the value in the submit function like so:

    $content_type = $form_state->getValue('content_types');
    $this->config('contentform.settings')
         ->set('content_type', $content_type)
         ->save();

I've also tried $form_state->get('content_types') and $form_state->get('content_types')->entity; But those didn't work either.

How would I get the node_type entity or object instead of just the label? Or is there a way to load the node_type from just the name?

You can load a node_type entity by specifying the node type id

$node_type_entity = \Drupal\node\Entity\NodeType::load($node_type_id);

or if you have multiple node types an array of entities:

$node_type_entities = \Drupal\node\Entity\NodeType::loadMultiple($node_type_ids);


How to get the URL of a file located in the theme folder? Is there a way to get the URL of an image located in the theme folder? Or just get the URL of the theme folder?

You can use drupal_get_path() to get the path to your theme folder:

$path = drupal_get_path('theme', 'name_of_theme');

From there you can specify a particular file like this:

$image_path = $path . '/images/image.jpg';

You could also use path_to_theme(), but be wary as the return from this can change depending on the context it's called in:

  It can point to the active theme or the module handling a themed implementation. For example, when invoked within the scope of a theming call it will depend on where the theming function is handled. If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme. When called outside the scope of a theming call, it will always point to the active theme.


Drupal Commerce product sale price using Rules I tried Rules like explained here enter link description here. It works but when it comes to checkout, order total amount displays 0. I've got no clue why. Here is my rule:

{ "rules_sale_price" : {
    "LABEL" : "\u0426\u0435\u043d\u0430 \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u043e\u0439",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "sale price" ],
    "REQUIRES" : [ "rules", "commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:commerce-product" ],
          "field" : "field_produkt_sale_price"
        }
      },
      { "NOT data_is_empty" : { "data" : [ "commerce-line-item:commerce-product:field-produkt-sale-price" ] } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "commerce-line-item:commerce-unit-price" ],
          "value" : [ "commerce-line-item:commerce-product:field-produkt-sale-price" ]
        }
      }
    ]
  }
}

I found the right way to do this: In the rule action I used Set the unit price to a specific amount instead of Set a data value.


Views Contextual Filters and URL Aliases Forgive me if this is a repost, but I have spent days trying to figure this out and everything I have found on drupal.stackexchange and elsewhere have been no help and I am struggling to understand the what views is doing exactly...  Here's my problem:

I have a website that has 2 different content types:  category and static content.

Within category content type, three pieces of content:  little, medium, and big.

In the static content content type, I have a autocomplete entity reference field called "Category" that points back to the category content type.   Next, I have three more pieces of content:

article1, article 2, article3.

Each has a unique title, no path alias set and the category reference field set to "little."

(Just using the "little" category for this question)

So, my goal here is to have the user enter the URL

www.example.com/category/article-title

and have a view generate the output (I don't want direct access to the node as I want to control all the content formatting).

Now, I can do a "simple" filter on the Content: Category (field_category) for "little" and the view will display all articles where that condition in met.  My problem comes in with the contextual filter and a URL alias.

No matter what I do in contextual filters, if I use a path alias, it will not work.  However, if I use a node number (in this case, 2 for "little"), it will work properly.  For instance:

www.example.com/little

will show no results.  But,

www.example.com/2

works (2 is the node number for "little").  In this case, the view generates output with content from node 4 (an article with the title "Little Brown Jug").  This is what it is supposed to do.

I have used both page view and block view, I have created relationships linking the content referenced and the content referencing the category field.
(I am sure this works as I can create related article pages with these relationships)

Whether I do this on the preview panel or directly on the URL, the results are the same. the term "little" generates no output, yet "2" does.

Any help here understanding this would be greatly appreciated.

I have added some screen shots

If you set the Views page path to node/% and add a Contextual Filter of Node ID and take the default argument from the URL you can use Views to override the node display.

However, this is probably not the best solution. You mention in your post that "I don't want direct access to the node as I want to control all the content formatting" but if you use the correct options you can fully control the node output. My recommendation would be to use Display Suite and control everything via the Manage Display tab of the content type and if necessary an override of node.tpl.php


access node title in field.tpl.php I would like to access the title of the node a field belongs to in a field.tpl.php file. My goal is to transform the field into a mailto link that would use the node title as the subject field.
Is it possible to access that information at this point?

You could get the node values from: $element['#object']: The entity to which the field is attached.

So in this case if the field is a node field the $element['#object'] is the node object.

print $element['#object']->title;

Documentation: https://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7


How to chage the page suffix? My page is starting from 0,and I want to start with1.
As follows:

Can implemented in Drupal?

Yes. Sort of.

The ?page=X query parameter in views pages is the offset from the SQL results (if you have the views admin section displaying generated SQL you can see this by the OFFSET X clause).

Hence, if you adjust your Pager options such that the Offset (normally 0) is set to opposite (e.g. -5) of the number in the Items per Page (e.g. 5) it will produce the effect of /my-views-page?page=1 containing the first results of your query.

However, it will also produce the side effect of the first offset page (i.e. /my-views-page and /my-views-page?page=0) of having no results. You could probably mitigate this through some URL rewriting, but it's a bit of work for something that has very little value (how many people browse the web thinking about numbered results vs. index offsetting?).


How to change the check box to radio buttons Yes/No in tableselect form api? How can I add a radio buttons with Yes/No options instead of the checkbox in the tableselect form (api)?

Here is the code in form.inc on line (3376):

$element[$key] = array(
        '#type' => 'checkbox',
        '#title' => $title,
        '#title_display' => 'invisible',
        '#return_value' => $key,
        '#default_value' => isset($value[$key]) ? $key : NULL,
        '#attributes' => $element['#attributes'],
      );

I changed the code like this:

$element[$key] = array(
        '#type' => 'radios',
        '#title' => $title,
        '#title_display' => 'invisible',
        '#options' => array(
          '1'   => t('Yes'),
          '0' => t('No'),
        ),
        '#return_value' => $key,
        '#default_value' => isset($value[$key]) ? $key : NULL,
        '#attributes' => $element['#attributes'],
      );

When I run it, it shows the form perfectly. But when I click the Submit button it gives me this error:

  "An illegal choice has been detected. Please contact the site administrator."

Any help?

You need to set '#multiple' => FALSE on the tableselect where you declare it. This will set the tableselect to use radios rather than checkboxes.


Commerce 2 Twig and Retail Price I have a use case that I need to add the retail price on a receipt twig next to the discounted unit price. Ive tried every possible field syntax I could think to try, looked everywhere and stumped...

{{ order_items.i_need_the_retail_price... }}

Is it possible to get that related field with twig syntax? It doesnt appear to be carried into Order Items.

After a few more hours learning twig filters I can calculate the retail price in each line item with this:

{% for adjustment in totals.adjustments %}
{% set disc_percent_remainder = 1 - adjustment.percentage %}
{% set disc_unit_price_raw_2 = order_item.getUnitPrice|commerce_price_format %}
{% set disc_unit_price_raw_1 = disc_unit_price_raw_2|trim(' USD', 'right') %}
{% set disc_unit_price_raw = disc_unit_price_raw_1|trim('$', 'left') %}
{% set disc_unit_price = (disc_unit_price_raw * 100) / disc_percent_remainder %}
${{ (disc_unit_price / 100)|round(2, 'ceil') }}
{% endfor %}

This is a horrible work-around I'm sure, ruins any chance of multiple currencies and Im sure can be cleaned up a lot with nesting some of this. But, it comes up with the correct retail pice.


How to add a title attribute from a different field to a link produced by a view I have a view that uses one field to produce a list of links to content.

I want to add a 'title' attribute to the link produced by the view that takes its value from a different field.

How does one do this in Drupal 8?

You can achieve this by using   views Rewrite results feature, Rewrite your Link with checking Override the output of this field with custom text and put your markup there and with Replacement patterns put your title as  your link attribute title.

More details Provided by @Raf

Thanks to zhilevan for pointing me in the right direction. After much trial and error this is the only thing I got to work other than completely rewriting the input with custom html.

I needed to add a "path to content" field. Note my fields are called 'field_heading' and 'title' respectively.

Note: the field that will actually host the link has to be at the bottom of the list. I wasted ages trying to figure out why I couldn't target my title text before realising this...

You need to uncheck "Link to content" in the setting for the host field - in my case 'Heading'

In the 'Rewrite output' section you need to actually provide a link or it will not work - or at least I could not get it to work without it. So the 'path' field I added earlier was used here as the path for the link. I could then add title field to the title attribute. You can see the available replacement patterns in the drop down with that name.

and the title attribute override...

Anyhoo, that was what i had to do to get it to work. Hopefully it is useful to someone else. I would love to see a simpler way to do this.


Use theme_get_setting to get a value I am using theme settings in my Drupal 7 theme to provide a theme option as follows:

$form['layout']['body_image_position'] = array(
  '#type' => 'select',
  '#title' => t('How should Body Image be Positioned'),
  '#options' => array(
        'body_image_position_right' => t('Image on Right'),
        'body_image_position_bottom' => t('Image on Left'),
        'body_image_position_left' => t('Image Below'),
         ),
  '#default_value' => 'body_image_position_right',

);

I then use theme_get_setting('body_image_position') to call the value of the setting.

Using this command returns the 'machine name' of the setting (e.g. 'body_image_position_right '). But I want the 'friendly name' (e.g. 'Image on Right'). How can I do this?

The easiest way would be to use a helper function to provide your positions which you can then reference back to. For example

// In the form function
$form['layout']['body_image_position'] = array(
  '#type' => 'select',
  '#title' => t('How should Body Image be Positioned'),
  '#options' => MYTHEME_position_settings()
  '#default_value' => 'body_image_position_right'
);

function MYTHEME_position_settings() {
  return array(
    'body_image_position_right' => t('Image on Right'),
    'body_image_position_bottom' => t('Image on Left'),
    'body_image_position_left' => t('Image Below'),
  );
}

// In the retrieval function
$key = theme_get_setting('body_image_position');
$settings = MYTHEME_position_settings();
$friendly_name = $settings[$key];

The form submission will essentially ignore the label for checkboxes/radios/select lists as it only deals with the key so you'll need to implement some sort of mechanism like this to get at your original labels.


"message": "X-CSRF-Token request header is missing" When using postman to fire post request I get this message. Does anyone has idea how to disable it? In this case it is post to register user so no authentification is required.

This is not recommend to remove the X-CSRF-Token. Instead you should get the token from  /rest/session/token and add this token in your header with this value.

But if you want to disable it you can write this below line to your settings.php file  $conf['services_csrf_token_check_disabled'] = TRUE;


Uninstall module for which an update is pending? I have a module for which an update is pending (drush updatedb). Unfortunately the update fails, blocking other updates of course (since it seems impossible to update selectively).

Is it safe to I pm-uninstall the module? Will this automatically delete the pending update? Or do I risk ending up in an even worse limbo?

[ As noted in the comments, taking a database dump and then restoring if anything goes wrong is an option; I'm still curious if there is a general rule about uninstalling while db updates are pending) ]

(BTW the module is service_links)

Slight correction to Clive's comment above: as soon as you disable the module, it is inactive in the system tables. When you uninstall it, all of its data is erased from the database. The fact that a module has pending updates won't affect the operation of disabling or uninstalling it, but beware of re-enabling a module that has been disabled for a period of time.  For way too much information on this subject, see: https://drupal.org/node/1199946


How to display contact form module in a block using drupal 7 Possible Duplicate:
  Put Site-Wide Contact Form in a Block

I want to display the contact form in a sidebar of the website. Is it possible? Please help me.

Check this answer which recommends to use Form Block module.
This could also be useful.


Programmatically render HTML in taxonomy term description I'm facing an issue where I'm attempting to programmatically set the description property for a taxonomy term that includes HTML, but the HTML is being rendered as text, rather than being rendered into HTML elements, unless I manually access the term in a browser and save it.

Example

taxonomy_term_save((object)array(
  'name' => $name,
  'description' => $t('
My description.

More info.
'),
  'vid' => $vocab->vid,
));

When I attempt to render the description, it appears as:

My description.

More info.

However, if I then go to Structure > Taxonomy > My_Vocabulary > My_Term and simply save the term (without any edits), it will then render properly as:

  My description.More info.

I've also made a number of attempts to achieve this through an Entity Metadata Wrapper, but no luck (though I am admittedly not well versed on EMWs).

How can I programmatically force the description to correctly render the HTML without having to manually re-save it?

Any help is appreciated!

The taxonomy_term_data table, which is the entity table for taxonomy terms, has a format column which stores the name of a filter to apply to the description when rendered.

It's available as a property on the entity, so you can use:

taxonomy_term_save((object)array(
  'name' => $name,
  'description' => $t('
My description.

More info.
'),
  'vid' => $vocab->vid,
  'format' => 'full_html',
));


count entityreference multivalue field conicidences (make an attendance form) This question is similar to this one How to make an attendance form, but i solved by entity refrence view widget module, saving date in a node, and having a field entityreference user relation with unlimited values. Now i have a views table of nodes like:

and now i can not sum how many times a user entityreference appears, ofcourse at the bottom i need to have: John=3, Mary=2, Pete=2
I tryed views aggregartor plus with no luck, please make some suggestions how to achive this.

Solved. This is what I did. In order to not make heavy loads i enebleded Entity Construction Kit (eck) module, then by rules i added an entity (instead of a node) for every user entity reference value, within two columns, one for user name, and one for date in attendance. Now I can have a view (of entities) with two exposed filter on dates (beginning and ending dates) Then I override my views table tpl view with the following code. It displays a 2 column table, first: username, second: number of days that user has attendance.  the following code assumes that username is second field on your view ($fieldloop == 2 ). code:

<?php $names = array(); ?>

<?php foreach ($rows as $row_count => $row): ?>
   <?php $fieldloop = 1; ?>
    <?php foreach ($row as $field => $content): ?>
    <?php if ($fieldloop == 2 ) {$names[] = strip_tags($content);} ?>
    <?php $fieldloop = $fieldloop + 1; ?>
    <?php endforeach; ?>
<?php endforeach; ?>

  <?php $attendances = (array_count_values($names)); ?>

Alumno	# dias

<?php foreach ($attendances as $attendance => $value) : {
?>
  <?php print $attendance ; ?>
 <?php print $value; ?>

<?php } endforeach; ?>


How to have different style files in multilingual website using Drupal? I have been developing a multilingual website using Drupal 6. The languages are English and Spanish. I want to have some different backgrounds and css for them. But both use just style.css.

How can I create different style.css file for them? For example style-sp.css for Spanish one and en-style.css for English one ?

Is it possible ?

you can do this in template.php:
you have to copt css file in themefolder/css.

    function yourtheme_preprocess_page(&$vars) {
        global $language ;
        $lang_name = $language->language ;
        if ($lang_name=='en')
        drupal_add_css(path_to_theme(). '/css/en-style.css');
        elseif ($lang_name=='sp')
        drupal_add_css(path_to_theme(). '/css/style-sp.css');
        $vars['styles'] = drupal_get_css(); //  use drupal_get_css() to add new css
}

so you have one of css files related to current page language.


ajax pager working depends on if js file is loaded in module .info file I'm using the code I've outlined in my blog post for a custom image search, and I'm having a problem with the pager, but only on one site. The first page of results renders just fine, but when I try to go to a subsequent page, I get a white screen with JSON; the page modal window is not rendered.

Here's the relevant code where it breaks:

  $form_state['values']['title'] = t('Search Results - Page !page', array('!page' => $pager + 1));
  $output = ctools_modal_form_render($form_state['values'], $build);

  print ajax_render($output);
  drupal_exit();

What's weird is that I have this exact same code working on two different sites, and it works fine on one, but not the other. I've looked at every possible variable I can think of, and they're all the same:

Drupal core version
jQuery version
module code (custom and contrib, Filefield Sources in this case)
form output sent to ajax_render
returned output from ajax_render

What else could I be missing that causes the JSON not to be rendered? I'm not looking for code specific info, just bigger picture items I could be missing.

Thanks.

UPDATE: So it looks like the problem has to do with the loading of my Drupal behaviors js file (seen at the bottom of this post. If I load it in the module .info file, the pager works fine, but if I attach it anywhere else - either to the node edit form or the ctools modal form - the pager chokes. I've inspected the page, and my js file is loaded in the page and ctools classes assigned to the pager buttons before clicking the pager, so it's not like they're not there. Unfortunately, for some reason, loading this file in the .info file causes other problems, so we can't do it globally.

But why would the method of loading the file make a difference as long as it's loaded?

It is the Drupal behavior JS code copied form your blog post.

(function ($) {
  Drupal.behaviors.addCtoolsModalClass = {
    attach: function (context) {
        $('#modalContent .pagination ul li a').addClass('ctools-use-modal');
        $('#modalContent .pagination ul li a').addClass('ctools-modal-imgsearch-modal-style');
    }
  }
})(jQuery);

The most meaningful thing I can find here is the class name ctools-use-modal. Obviously, this class name is used for ctools module. So I search this class name and find below snippet from js/modal.js in ctools module (version 7.x-1.9).

  Drupal.behaviors.ZZCToolsModal = {
    attach: function(context) {

      $('area.ctools-use-modal, a.ctools-use-modal', context).once('ctools-use-modal', function() {
        var $this = $(this);
        $this.click(Drupal.CTools.Modal.clickAjaxLink);

Now we have the full picture.

In your JavaScript code, you want to add a class name which is required for Ctools JavaScript code. AJAX does not work because the Ctools JavaScript code is run before adding the class name, so Drupal.CTools.Modal.clickAjaxLink never bind to the link.

Yu can fix it by manually run the attach behavior again after adding classname.

Solution

(function ($) {
  Drupal.behaviors.addCtoolsModalClass = {
    attach: function (context) {
        $('#modalContent .pagination ul li a', context)
          .addClass('ctools-use-modal')
          .addClass('ctools-modal-imgsearch-modal-style');

        Drupal.behaviors.ZZCToolsModal.attach(context);
    }
  }
})(jQuery);

Note: since all the code inside Drupal.behaviors.addCtoolsModalClass is wrapped with jQuery.fn.once, which means every code inside is only be implemented once if the selector finds the element. So you don't need to worry about binding the same event twice.


How to periodically deduct user points for flagged nodes? I have a node which is published. And I have a global flag, which users have to mark to make nodes visible in Views. This is easy to do.

But then I need to charge 40 user points for every day that node remains flagged. And when user doesn't have enough points anymore, then node must be unflagged.

Possible realization what I tried:

via CRON: I tried to make a rule for that, but when I add an Event (= On CRON Run), then I cannot add an action with user points. Some people say it should be an extra script for cron, but I don't know how to make it.

via Rules: I tried to make a rule on Event "When node is flagged" and make a Scheduled Rule with the same -40pts for user nextday. It works only once until the Scheduled Rule completed or until cron is running. So I cannot make a loop properly.

I've no more ideas to get it working. Maybe I just lost something while making Rules?

Part 1 - Deducting user points

Repeat the daily deduction of user points

Use the rules scheduler as explained in the video about "Repeating scheduled events". The "clue" here is:

as the last action of your rule, you reschedule the same rule to be executed again after +1 day(s).
the very first time you need to trigger the execution of this rule manually (from the Rules UI). Or you can use the Rules Event "when node is flagged".

Video tutorials

If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework.

Part 2 - Stop deducting if insufficient user points

The 2nd part of your question is about "... when user doesn't have enough points anymore, then node must be unflagged ...". The challenge with that is that there is no Rules Condition like "If user has less then X user points".

However, to also make that work, you can use a Rules Action "Load user points of a user", as an alternative (work around?) for something like a missing Rules Condition to "check the current user points for a user". Have a look at my answer to "How to create rule to change user role based on points (using User Points module)?", which includes an sample rule that uses this Rules Action.

So all you have to do is to further enhance your rule as in Part 1, by using the Conditional Rules module so that your Rules Action will look something like so:

  Load user points balance

  If user points balance > 40

  then reschedule the same rule to execute in 1 day.


How do I programmatically update or delete menu items? I have seen the post on how to create menu items programmatically in Drupal 8, but how do I update or delete menu items in D8?

Clarification: by programmatically I mean dynamically so yaml config files are not going to help.

First you will have to load the entity. Either way works:

$menu_link = MenuLinkContent::load($menu_link_id);

or ...

$menu_link = \Drupal::entityTypeManager()->getStorage('menu_link_content')->load($menu_link_id);

Next you can update value using set() method or through the magic method __set...

$menu_link->expanded = TRUE;

To save, simply call the save() method.
To delete, simply call the delete() method.


How to display 'Terms and conditions' before starting a download, possibly using Rules? We have a page displaying various download options. When the user clicks one of the options we would like to display a terms and condition page and then take the user further to the actual download page.

There is only one terms and conditions but multiple download pages.

I looked at the Legal module. But this seems to be for users who register and users don't need to register for download.

I also looked at Rules module. But this is for recurring events. But it is not a recurring event but an on click event.

Has anybody got an idea which strategy would be helpful here?

Note: terms and conditions are the same for every option.

It should be possible to implement a procedure that fits your requirement, using a combination of the Rules and Flag modules. Here is how you could do so:

Create a Flag (using the Flag module), related to your "terms and conditions" page (=TOC). The actual perpose of your flag is to have the user "flag" the TOC-page to confirm something like "I agree to the terms and conditions".
For any of the relevant download pages, try to have a path for each of them that starts with something like downloads/. It can be any path you like, just make sure it's something that uniquely indicates "this is one of the download pages for which we want to make sure the user agreed to the TOC as on the TOC-page".
When the user then requests the download page to be viewed (opened), add a rule that is a variation of the rule I included (in export format) in my answer to the question about How to restrict access to a node via node/12 and allow access via a path like content/sometitle?

These are the changes to that rule to make it work for this case also:

Change node to downloads (as in my assumptions above in "2.").
Add a Rules 'Condition' like "If this user did NOT flag the TOC-page yet".
Change the "Message" (in the Rules 'Action'- to something to indicate that the user must first "accept the TOC" (by flagging the TOC-page, as in "1.".
Add an extra Rules 'Action' to issue a redirect from the selected download page to ... you guessed it ... the TOC-page!

Haven't experimented/tried creating this Rule (= variation of the rule in the answer I mentioned above), but pretty sure it'll work. Hopefully you'll be able to complete the rest of the puzzle in my answer on your own (if not let me know where you get stuck and I might enhance my answer for it also).


User rights: Only create, edit and publish articles There is a user role where users can edit, save and publish articles. But they don't see the admin menu.

Does exist a module to realize a "create content" button only or to modify the admin menu?

There is no specific module for that, and it is well known problem. But if you want them to only create one content type, like Article, you don't need a module for that. You can simply go to /admin/structure/menu and add links like /node/add/page to a menu they can access.

For node listings for such users, create a view with table of titles and edit links.


How to call one file functions in other files in custom module? I have created custom module in Drupal 7.

I want to create one file and in this file I want to create all functions that I need to use in this module. I want to call these functions in .module file. So for this what file and how can I use these functions?

It's PHP, so you use require or include to include functions from other files.

Drupal's wrapper around those is module_load_include. Examples from the docs:

// Load node.admin.inc from the node module.
module_load_include('inc', 'node', 'node.admin');
// Load content_types.inc from the node module.
module_load_include('inc', 'node', 'content_types');

Only use this function inside another function, not in global scope. If you need to unconditionally depend on a separate file for a whole module, just use require_once or whatever makes most sense for your use case.


How to find whether the term is first or last in a vocabulary? I am using a vocabulary to get the list of terms in it. The tids for the terms are 1, 2, 3, 4, 5. I have no hierarchy in my taxonomy. Now I would like to find whether 1 is the first term in the vocabulary, similarly to find whether 5 is the last term in the vocabulary.

Is there any API way of doing this?

First, you need to obtain one level of your taxonomy terms. Use either taxonomy_get_tree($vid, 0, 1); for top level ones, or taxonomy_get_children($tid) for children of a known element.

It should be sorted the way you want it, as both functions contain this in their code:

$query->orderBy('t.weight');
$query->orderBy('t.name');

Now you can use standard PHP functions reset(array &$array) and end(array &$array) to get first and last object from that array for comparison. Note that this will move internal pointer around, so don't use them lightly on arrays you also use elsewhere already.


How can I show/hide just one menu item based on user role? I have a single menu item that I would like to show or hide based on user role.

Use case: I have a membership site with paid and free memberships.  In the navigation menu, I want to show a link for users who do not have the "paid" role to the "Upgrade your account" page.  There's no need to limit access; I simply want to show or hide the link.

I know I could make a separate menu and restrict access to that menu block by role, but is there an easy way to do the same for a single menu item link in an existing menu?

You may try Menu per Role

  This module allows you to restrict access to menu items1 based on user
  roles. It depends on the Drupal core menu.module—just activate both
  modules and edit a menu item as usual. There will be a new fieldset
  that allows you to restrict access by role. The fieldset also appears
  in the node edit form.

D7 release is not stable yet its 7.x-1.x-dev


Drupal 6 - Theme custom search form results I have a custom search form written in my custom-module. On submit, i have used do_search api and then I have made some modifications/customization with the results.

Now having my customized results, how can I render them?

Work so far--->

In custom-module.module

function custom_module_search_ticket_form_submit($form, $form_state) {
   // do_search()
   //  customizations (in the sense, removed few results according to my requirements. Otherwise the result-object/array format is same as of core search results)

    return theme('rootcandy_my_search_results', $results, $type);
}

function custom_module_theme() {
  return array(
    'rootcandy_my_search_result' => array(
      'arguments' => array('result' => NULL, 'type' => NULL),
      'template' => 'rootcandy-my-search-result',
    ),
    'rootcandy_my_search_results' => array(
      'arguments' => array('results' => NULL, 'type' => NULL),
      'template' => 'rootcandy-my-search-results',
    ),
  );
}

Rootcandy is the theme I have used. In rootcandy's template.php

function rootcandy_preprocess_rootcandy_my_search_results (&$vars)  {
  // copied lines from core search module's search.pages.inc function template_preprocess_search_results(&$vars)
}

function rootcandy_preprocess_rootcandy_my_search_result (&$vars) {
  // copied lines from core search module's search.pages.inc function template_preprocess_search_result(&$vars)
}

Under rootcandy theme folder, Added below tpl.php files

rootcandy-my-search-results.tpl.php  (copied from core search's search-results.tpl.php)
rootcandy-my-search-result.tpl.php   (copied from core search's search-result.tpl.php)

Now I have done this much, clearing cache, after everything; Submitting my custom-search-form renders nothing, other than the form. When I print my customized results, they are fine. Theming part is not working.

Where is the mistake? Plz help !

Whatever u have done so far is correct. Only thing left now is to render the content from ur preprocess 'rootcandy_preprocess_rootcandy_my_search_results' to ur 'rootcandy-my-search-results.tpl.php'. U have to start debugging in this way.

Check ur $vars['form'] contains ur form values in  'rootcandy_preprocess_rootcandy_my_search_results'
create a variable in preprocess and try using it in ur rootcandy-my-search-results.tpl.php.
Eg: $vars['testing'] = "this is to confirm that variable is working in rootcandy-my-search-results.tpl.php"
if you print $testing in ur rootcandy-my-search-results.tpl.php and it gives "this is to confirm that variable is working in rootcandy-my-search-results.tpl.php" Which means its working fine.
Then you can pass ur form results to the tpl file.
Eg: $vars['result'] = drupal_render($vars['form']['result']);

Try this. Ur first goal will be making sure u can get ur preprocess values in ur tpl file.


Alter Views exposed filter form I'm trying to add more elements to the exposed views filter form but am running into an odd problem that is confusing the heck out of me.

I'm using a hook_form_alter call in a custom module to add new select drop downs.  This works great, except that they get rendered out as part of the submit element.

function my_module_form_alter(&$form, &$form_state, $form_id) {
  $form['test'] = array(
    '#type' => 'select',
    '#title' => 'New Filter',
    '#options' => array('value 1', 'value 2')
  );
}

Rendered it looks like this:

       Approval Status

          <select name="node_status" class="form-select" id="edit-node-status"><option value="All" selected="selected">&lt;Any&gt;</option><option value="0">queued</option><option value="1">approved</option><option value="2">denied</option></select>

    <input type="submit" id="edit-submit-wpg-content-bulk-admin" value="Apply" class="form-submit">

      New Filter:
      <select name="test" class="form-select" id="edit-test"><option value="0">value 1</option><option value="1">value 2</option></select>

Does anyone know what I'm missing here?  Why would the newly added 'test' element be rendered inside the submit element wrapper?

You need to turn the new form item test into a widget by declaring the item in $form['#info']

So your code should look like the following:

function my_module_form_alter(&$form, &$form_state, $form_id){
  $form['test'] = array(
    '#type' => 'select',
    '#title' => 'New Filter',
    '#options' => array('value 1', 'value 2')
  );

  $form['#info']['test'] = array(
    'value' => 'test',
  );
}


How to use 'use-ajax' class with pages created by controller? I'm trying to use 'use-ajax' class to load a page inside a modal box.

My Page is dynamically created using node id pass on my page controller

My link looks like this

Any idea on how can I achieve my goal?

This is a render array that create a link that open a modal windows.

use Drupal\Core\Url;

public function build() {
$output = array();
$output['overlay_link'] = array(
  '#type' => 'link',
  '#title' => $this->t('Add an activity'),
  '#url' => Url::fromRoute('node.add', ['node_type' => 'event'], ['query' => ['destination' => $destination],
    'absolute' => TRUE,]),
  '#attributes' => [
    'class' => ['use-ajax', 'button', 'secondary'],
    'data-dialog-type' => 'modal',
    'data-dialog-options' => \Drupal\Component\Serialization\Json::encode(['title' => t('Add an activity'), 'width' => 800,]),
  ],
);
 return $output;
}


What is efficient way of updating drupal commerce product prices when your on a product display page? What are some fast ways of updating the product prices for drupal commerce? Right now i have to go into the product list and search for the items I want to change prices on. I know inline entity form solves the issue, but was wondering what other methods are other people doing?

You can make a nice edit contextual links with custom_contextual_links module in any view you would like to use this functionality.


Display author profile fields in nodes created by that user I have a user profile with extra fields like company address and company name etc.

I also have a content type job where i'd like to use the author's profile info (company name, address) in the content created by that author.

How do I use fields from the author profile in my nodes created via the job content type?

Is there something like a token field that I can use in my content type to display profile fields?

I know in views there's an option to use relationships, but I'd like to not use views for this if possible.

1)Go to admin/config/accountsetting then manage field add fields (company name, address  and company name) into it.

2)Go to your content type job add fields (company name, address  and company name) as a existing field not as a new field.find your existing field from the list of available dropdown and select it and save.


Drupal commerce change quantity textfield in cart view to selectbox Is there a way to change the quantity widget in the Drupal Commerce cart view from a textfield to a selectbox? And then refresh the page when the selectbox is changed without making the user press the Update cart button?

<?php
/**
 * Implements hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
 if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
   if (isset($form['quantity']) && ($form['quantity']['#type'] == 'textfield')) {
     $form['quantity']['#type'] = 'select';
     $form['quantity']['#options'] = drupal_map_assoc(range(1,10));
     $form['quantity']'#default_value' => 1,
   }
 }
}

?>


Display node's languages in views do you think, it is possible to display in views the languages the node was translated to?
I mean something like this:

First article
english|german

Second article
english|german|dutch

Yes it is possible.

I have done something similar in Drupal 7 some time ago. Here is how to do it:

Create your View

Create a Fields style View with your required filters and sorting

Add the relationship to the Translations

Add a relationship to the translations: Content translation: Translations
As Translation option choose All
Add a filter Content translation: Language and choose Current user's language

Add the Fields

Add the field Content: Title with no relation and with Link this field to the original piece of content disabled
Add the field Content translation: Language with the Translations relation added before and with Link this field to the original piece of content enabled
In the Format Settings choose Content: Title as Grouping Field

Format the list

The horizontal list of the languages can be achieved by CSS formatting


Attach a Webform to user registration form Is there any way to do this in Drupal 7?

I want new users send some documents via Webform on registration.

The reason is that I don't want to save these documents as an user profile field.

It sounds like you want the Webform Registration module. It lets any webform create users upon submission. It also lets you customize the registration process by selecting which webform elements are associated with the newly created user's name, password, & email.


how should I hide the menu and url setting in from alter? I have a node/add/blog form,
there are some things I don't want show it.
I give the elements

$form['author']['#access'] = FALSE;
$form['options']['#access'] = FALSE;
$form['comment_settings']['#access'] = FALSE;

but I cann't find what's the element name for menu and url setting in message of dpm($form);

As explained in hook_form_alter

  The call order is as follows: all existing form alter functions are
  called for module A, then all for module B, etc., followed by all for
  any base theme(s), and finally for the theme itself. The module order
  is determined by system weight, then by module name.

  Within each module, form alter hooks are called in the following
  order: first, hook_form_alter(); second,
  hook_form_BASE_FORM_ID_alter(); third, hook_form_FORM_ID_alter(). So,
  for each module, the more general hooks are called first followed by
  the more specific.

So, your module hook_form_alter is called before path module or menu module which adds those elements. That's the reason you can able to see those elements when you print form in your custom module.

Try using same form alter hook in your theme template.php it should work. It worked for me ! I can able to see path settings and menu setting. See for Seven Administration theme below.

function seven_form_alter(&$form, &$from_state, $form_id) {
  drupal_set_message("<pre>" . print_r($form, 1) . "</pre>");
}

Else, you need to alter your module weights !!


Role based menu redirect Setup:

I have a main module (called public) and several sub-modules that extend the support offered by the public module.
A sub-module (let's call it sub) functions can be accesed only by users with the role that that sub-module creates (guess what, called sub).

Some of the pages defined in public_menu() are extended by the pages defined by sub_menu().

For example, if the public module declares:

$pages["public/asl/info"] = array('page callback'=>'public_asl_info', ...);

the sub module declares:

$pages["sub/asl/info"] = array('page callback'=>'sub_asl_info', ...);

also, consider that sub_asl_info() extend public_asl_info() like this:

function sub_asl_info( $id)
{
    $public_page = public_asl_info( $id);
    $dip_page = sub_asl_dip_info( $id);

    $page = $public_page.$dip_page;

    return $page;
}

there are more complex cases, but this is enough to explain the setup :)

How i solved it (wrongly) so far:

function sub_menu_alter( &$item)
{
    if( !has_role( 'sub'))
        return;

    $item['public/asl/info']        = $item['sub/asl/info'];
    $item["public/operatori/info"] = $item["sub/operatori/info"];
    $item["public/ospiti/info"]     = $item["sub/schedario"];
    $item["public/query"]           = $item["sub/query"];
    $item["public/tassonomia"]  = $item["sub/tassonomia"];
    $item["public/comunicazioni"]   = $item["sub/comunicazioni"];
}

The redirects are hard saved inside the menu_router table, so with more than one user logged it doesn't work.
I came to this solution based on how i solved the same problem but for blocks, however, using _block_view_alter() doesn't hit the same wall.

How do i solve this (programmatically)?

Possibly without using yet-another-module, unless really neccessary.

The final solution was much easier than i could possibly hope for.

I ended defining my own hooks and allow the sub-modules to implements the changes using said hook,s after checking the role of the user.
Using the example above, it became:

function sub_asl_info_alter( $page, $id)
{
  if( has_role('sub'))
    $page->content .= sub_asl_dip_info( $id);
 }


Add comments on user profile How do you add a comment form on your user profile in Drupal 7? I have installed panels but I don't know how you add the comment form on the users profile

I believe that the user profile is not a type of "node" so it is invisible to Panels.  Therefore, you will most likely need to write a custom module that will inject the comment form into the user's profile page.


Primary menu not showing when lanugage is changed? I have installed following modules :

1.Locale
2.Content Translation
3.Internationalization
4.Block translation
5.CCK translation
6.Content type translation 7.Menu  translation

I added Arabic language .po file using admin/build/translate/import. I added one menu item for English and another menu item for Arabic in primary links. The menu items added for English are displayed on a node view page (when English is selected from language switcher) but the menu items added for Arabic are not displayed on a node view page (when Arabic is selected from language switcher).

Since Menu items are user created the Locale module cannot translate them all.. You have to manually create translation for each menu item for both the languages and it maps according to the language.


Display view items as thumbnails I would like to make a view created as a block where every item is displayed as a thumbnail of a cover photo-field of the content type.

I can't find this option in the display options dropdown ... How should I go about it?

In Drupal 7, you just need to use Image style as answered by Jack-PL


How to upload files under taxonomy? Suppose in a School's website, I have some departments. They want their class lectures, class routines, course curriculum to be uploaded under their departments. Typically we did some very simple things - all the departments are now simple hierarchical pages. How to go with it.

We thought to go with a new content type, where the taxonomy will be the department name, where under the department names will be the type of document (whether class routine, or class lecture etc.) and under that taxonomy if we write a content, then we can go through the taxonomies to the content. In a scene they will be:

Home
  - Departments
     - Zoology
       - Class Lecture
         - Content
       - Class Routine
         - Content
       - Class Curriculum
         - Content
     - Biology
       - Class Lecture
         - Content
       - Class Routine
         - Content
       - Class Curriculum
         - Content

BUT NOT the file directly. We need to attach file under taxonomy, not the content. So there is a problem.

How can we proceed to such extent?

You can attach file with taxonomy as below:

Go to Administration -> Structure -> Taxonomy
Edit Vocabulary, which you want to use, from the list of Vocabulary.

Click on "Manage Fields" tab in the top of the page.

Add new field of field type as file and assign the required file extension which you want to upload and save the field.

When you create new term of the vocabulary, it will allow you to upload file with term.


Delaying form submission via Javascript doesn't work in IE I have a form built for creating an instance of a custom entity. Upon submitting the form, I have a jquery script completing some actions on the page that need to execute before the form submits, so I attempt to stop the default event, perform those actions, and then resume the event as follows:

$('#submit').on('click', function(event){
    if (valid === true) {
        valid = false;
        return;
    }
    event.preventDefault();
    valid = true;
    //do some stuff
    $(this).trigger('click');
});

This works perfectly in Chrome, but unsurprisingly does not work in IE11. Through console logging I see that the re-click is fired, but the return line  simply does nothing, so the button click does not submit the form at all. I have tried some alternatives to $(this).trigger('click'); explained in a stackoverflow thread, but nothing is getting it to work.

The reason I'm creating a Drupal-specific thread about it is that I also tried  to skip re-firing entirely and just do a form submission like this:

$('#submit').on('click', function(event){
    event.preventDefault();
    //do some stuff
    $('form[data-drupal-selector="my-form-id"]').submit();
});

But this, for whatever reason, clears all of the data in any field collection items contained within the form.

Is there any feasible way to do what I'm trying to accomplish in Drupal that works in all modern browsers?

Try doing something like:

 $("form").submit( function () {
   //do something
   return true;
 }

Source


Drupal-7 - Lists and Custom Content Types I've just started with Drupal-7 coming from Drupal-5 that I last used a few years back and made a few customisations too. It seems to be Drupal-5 was much easier for modification, though Im starting to work out where all the data is saved processing through all the examples.

What isn't clear is when is a node not a node. For example, there are various support lists that I would like in my customisations, for example "salutation" (mr, mrs, miss, dr, revd etc) that should be user maintainable and stored in a database. It seems a bit overkill to create a separate content type and node just for this.

The current project Im working on is for Events, but I need to sub-categorise those Events twice by Event Type and Sub-Event-Type. Both of these should be user maintainable and therefore database driven. I can put them in a Content Type/Node but it does seem overkill.

I can't figure out if there's a programmatical way to insert, alter, delete (like the old days) into their own tables and then reference them in the Event node I will create generating a dynamic list.

There are lots of information out there about using Values, Taxonomy and Views etc. Seems everybody shys away from programming now and there's no examples anymore!

Any thoughts where to start? It seemed much easier finding the information before.

Organizing content with taxonomy (category) is a very powerful tool of Drupal.

  What isn't clear is when is a node not a node. For example, there are
  various support lists that I would like in my customisations, for
  example "salutation" (mr, mrs, miss, dr, revd etc) that should be user
  maintainable and stored in a database. It seems a bit overkill to
  create a separate content type and node just for this.

According to this, you can manage "salutation" with taxonomy . The"salutation" is a vocabulary and "mr, mrs, miss, dr, revd" are terms of the vocabulary. They will be stored in the taxonomy table and the path admin/structure/taxonomy/your_vocabulary will be user maintainable list page.

You can create a custom field ( term reference ) to your vocabulary ( "salutation" in this case ) for your content type.
They can be chosen from a list when user creates a node.

Same concept for your Event Type and Sub-Event Type.
The Taxonomy Manager module may help you.


Display content based on taxonomy with view I have a hierarchical taxonomy like the following:

Bachelor of Degree

Year1 (child term of Bachelor of Degree)

Term1 (child term of Year1)

Year2

Term2

The body text of content1, content2, … of a content type will go under the terms term1, term2, ….

Can you kindly help me in getting the view with the following structure?

Bachelor of Degree

Year1 (child term of Bachelor of Degree)

Term1 (child term of Year1)

content1
content3

Year2

Term2

content2
content4

You would use /taxonomy/term/% - which is a default view, you don't have to create it. The view should show Fields of body content or whatever other fields you you have associated with the node that you wish to display.
Your content types also need to have fields where the correct taxonomy categories can be selected when creating the node.
Your view "Sort" and "Filter" criteria will determine how these nodes are ordered.

To preview your view, use /numerical term ID of your taxonomy term

To get your nodes to display, create a menu with the same parent-child structure as your taxonomy terms and set the menu paths as the taxonomy term ID. You would then display this menu as a block either on a page or in a sidebar.


How to group two fields while creating content type? I wanted to a content type which get number of title and links. And I want an option which allows the user to add more title and links. The fields in the content type are

   1. Promotional Image
   2. Image Alternative Text
   3. Title
   4. Links

In the above mentioned field. I wanted to group only the Title and Links field. I wanted to give add more option for those two fields alone. Can anyone tell me how this could be done. I cant establish a link between those two fields. At present when I select the 'number of values' option in field settings it gives me add more button to each field but I am not able to link those two fields with any relation. Can anyone please suggest me a solution?

If you want to group fields together to be accessible as a single field on your form, the easiest way is using the Field Collection module. It:

  Provides a field-collection field, to which any number of fields can be attached.

Using that you can group your Title and Links fields into one, and you'll have an 'Add more' button for the group, rather than for each individual field widget.


watchdog table grows too big too fast On a rather busy D6 site, I need to truncate watchdog table very frequently, since it grows at about few Gigabyes per day. On the other hand I can not disable access logs to avoid the table's inflation. Running cron yeilds a lot of errors and does not seem to clean watchdog table. So what is the best way to deal with this problem?

Thanks

Without knowing what kinds of errors you are seeing, it is hard to say what to do.  If this is a live site, then I suggest that you edit your settings.php to turn off PHP error reporting.  IIRC, this will do it for you

error_reporting(0);
ini_set('display_errors', FALSE);
ini_set('display_startup_errors', FALSE);

or you could also edit your php.ini and do the same thing, or use the equivalent .htaccess directives.  You may get by with just turning off E_NOTICE.

If you are seeing favicon.ico errors in the in the log, then I suggest putting in a rewrite to point to the favicon in your theme, or at least on in one of the standard themes.

Another possible watchdog clogger are the internal connection messages.  You can try adding

# make sure internal dummy connections don't make it into drupal
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

to .htaccess if you are seeing them.

All of this said, if you are seeing several gigs of errors or warnings in your watchdog, then you have a serious problem with your site.  Clone the site to a development version, and figure out what is really going on:  fix the actual problem (ie, stop the errors) instead of curing a symptom (ie, hiding the error messages).


How to add vocabulary terms to a taxonomy category I'm trying to get my module to install a vocabulary on enable/install but something about adding terms to it isn't working. any idea why this function isn't working?

function _vocabulary_add_items() {
  $vocabulary = taxonomy_vocabulary_machine_name_load('usertype');
  if($vocabulary === TRUE) {
    $terms = array(
        (object) array(
            'vid' => $vocabulary->vid,
            'name' => t('Economy'),
            'description' => t('Basic user account'),
            'format' => '', // default
            'weight' => 0, // default
            'vocabulary_machine_name' => $vocabulary->machine_name, // optional
        ),
        (object) array(
            'vid' => $vocabulary->vid,
            'name' => t('Deluxe'),
            'description' => t('Deluxe user account'),
            'format' => '', // default
            'weight' => 0, // default
            'vocabulary_machine_name' => $vocabulary->machine_name, // optional
        ),
        (object) array(
            'vid' => $vocabulary->vid,
            'name' => t('Ultimate'),
            'description' => t('Ultimate user account'),
            'format' => '', // default
            'weight' => 0, // default
            'vocabulary_machine_name' => $vocabulary->machine_name, // optional
        )
    );
    foreach ($terms as $term) {
        taxonomy_term_save($term);
    }
  }
}

taxonomy_vocabulary_machine_name_load() returns an object or FALSE. You're checking for exactly TRUE by using ===.

Any of the following should work (sorted by my preference):

if ($vocabulary) {
if (is_object($vocabulary)) {
if ($vocabulary !== FALSE) {
if ($vocabulary == TRUE) { // only two equal signs here


Form #redirect not working? I'm trying to make the user creation form redirect back to the home page when you submit it. I'm using Content Profiles so it is two forms sharing a submit button. Even if I set #redirect = '/' on both forms the form always redirects back to itself. It works and everything, but won't redirect how I want.

Any ideas?

Code:

function mymodule_form_alter(&$form, $form_state, $form_id) {
      switch ($form_id) {
        case 'user_register':
        $form['#redirect'] = '/';
        break;
        case 'coordinator_node_form':
        $form['#redirect'] = '/';
    }
}

There are two facts to keep in consideration about $form['#redirect']:

$form_state['#redirect'], set in a form submission handler, takes the precedence over $form['#redirect'].
$form['#redirect'] and $form_state['#redirect'] are ignored for forms where "#action" has been set by a module. That is what happen with the user login form.
$form['#redirect'] and $form_state['#redirect'] are ignored when $_REQUEST['destination'] is set; its value is instead used.

If you want to redirect a form, and be sure it gets redirected to the path you set, you should implement hook_form_alter() to add a form submission handler that alters $form_state['#redirect']. The module implementing that hook should be executed after other modules that alter $form_state['#redirect'] for that module.
This doesn't have any effect, though, in the last two cases I listed before.


Horrible permissions bug, anonymous users can edit products I have a Drupal Commerce site. I'm using Content Access to only allow users with the role "Vendor" to "Edit own product." Nobody else is allowed to edit any products. This is the only module I'm using afaik that controls permissions.

And yet.... everybody is able to edit all products! Even guests! This bug is horrifying.

I've tried

clearing all caches
emptying the node_access DB table
Rebuilding permissions from the status report
completely disabling editing products for anyone
disabling and uninstalling the Content Access module

Here is my access control for the Product content type (it was originally called Produce, hence the machine name being produce)

And yet when I go to view a product, even as an anonymous guest, it shows the "View" and "Edit" tabs. And when I click "Edit" I can actually change the content and save the node!

One node example is node id 78. If I look at the node_access table in the DB, it shows this:

nid   gid   realm   grant_view   grant_update   grant_delete
78    0     all     1            0              0

If rebuilding permissions doesn't work, disabling Content Access doesn't work, then.... I have no idea where to go from here.

Update

I've installed Devel and am checking which modules implement hook_node_access

$ drush fn-hook node_access
Enter the number of the hook implementation you wish to view.
 [0]  :  Cancel
 [1]  :  commerce_marketplace
 [2]  :  node
 [3]  :  features

Node access rights can be a little hard to debug.  You need to enable the Devel module, and the Devel Node Access submodule.

Then goto your block configuration.  There will be two new blocks: Devel Node Access and Devel Node Access By User.  Add these to your page, and configure them for your admin role(s).  Also goto the Devel settings (admin/config/development/devel) and enable Devel Node Access debug mode.

Then visit a page with access problems.  Look at the debug info.

The Devel Node Access block will show you the {node_access} rows for the node in question.

The Devel Node Access By User block will show you who has permission to do what, and why.

Then you need to do some sleuthing.  If it is a permission, then you need to find that permission and edit it.  If it is a hook_node_access(), then you need to find the module that is implementing it.  If it is a grant, then you need to use the realm/gid and track down who is implementing a hook_node_access_records() with that pair.

The module_implements() function can be used to track down who is implementing what.  I typically do this with

drush php-eval 'print_r(module_implements("node_access"))';
drush php-eval 'print_r(module_implements("node_access_records"))';

My guess is that one of your features has a rogue hook_node_access() in it.  You could also try disabling your features one by one and seeing what happens.


PDOException: SQLSTATE[HY000]: General error: 1 cannot rollback I have managed to cause this error while working with exposed filters weighting in views.
Any idea how I can correct it? I am running Sqlite for database. Is it possible to clear transactions or something?
Thanks

Additional uncaught exception thrown while handling exception.
Original
PDOException: SQLSTATE[HY000]: General error: 1 cannot rollback - no transaction is active in node_save() (line 1152 of /home/site/public_html/modules/node/node.module).
Additional
PDOException: There is already an active transaction in dblog_watchdog() (line 154 of /home/site/public_html/modules/dblog/dblog.module).

Turns out it was a problem with my /tmp directory being full.. Devel module had filled it up.
It's something to be aware of and here is a script to notify you when /tmp is nearing full http://forums.ultratechhost.com/thread-187.html


How to detect if "Show end date" is checked? Trying to find a way to get the value of the checkbox "Show end date" on a date field on drupal 7.

Is it stored somewhere in the database? Can't find it.
Its definitely not in the $node object.

Any ideas?

It's stored against the field settings in the field_config table. You can get access to it through the API with field_info_field()

$field_info = field_info_field('field_name');
$to_date_setting = $field_info['settings']['todate']; // optional, required, etc


Uncaught TypeError jquery function is not read anymore I've on a Drupal 6 site which run since 2 years, a new problem at first with CloudZoom but i start to think that it's a little more than that.

I've errors in the firebug console which says :
Uncaught TypeError: Object function ... has no method 'cookie'
or Uncaught TypeError: Object function ... has no method 'cloudzoom'

So Cloudzoom don't works anymore on some language... what is strange is that it still work in english.

I've take a look at the code and it's ok, it worked in the past ans still work in english. I also make sure that JS file are call in the right order jquery>librairies>myOwnJs.

what i need is to understand the error message "Uncaught TypeError: Object function" : what can generate that kind of error, where to search. I spend a lot of time on that and don't really know where to look now.

You got it - basically it means the function isn't defined or is conflicting. You have to load the jQuery file that you're going to use and not multiple or you'll get that type of strange behavior.

The workaround I've used, which does work -- assuming you're not using that particular function -- is to define the function yourself as an empty function and it'll reference that and just keep on going. This came up in the Adobe Edge beta as fnCycle() was giving the same error. After putting the empty function in my own .tpl.php is solved and didn't kill the js execution.

Note though that while this may work for that one situation, you will have others if you leave conflicting versions of jQuery in there.


Drupal 7: "Maintenance mode" message when the site is NOT in maintenance (Yes, I´ve cleared cache, 4 times now) I get the "Operating in maintenance mode. Go online." message and the D7 site is not in maintenance mode.

The message doesn´t appears all the time, and sometimes it goes away when I refresh the page.

I´ve cleared cache. I´ve tested and it is most certainly NOT in maintenance mode.

I´ve checked Drupal Error reports, and I get this one (I don´t know it it´s related or not with the problem):

TIPO    acceso denegado
FECHA   Martes, 14 May, 2013 - 01:11
USUARIO Anónimo (-)
UBICACIÓN   http://www.liga.net/cron.php
REFERENTE
MENSAJE frontpage
SEVERIDAD   advertencia
NOMBRE DE LA MÁQUINA    xx.xxx.xx.xxx
OPERACIONES

Sometimes in a complete random way, as an anon, it appears the page "site offline". When I reload the page it´s up again...

Any thoughts on this will be very much appreciated. Thanks!

Search variable table in database. Variable named maintenance_mode should be there, and should be a serialized representation of false (or numerical 0). If it's not, your site will have a problem.
If this appeared after upgrade, re-running update.php might help


Add tabs to a view-page What I want to achieve is rather simple but either I haven't drank enough coffee yet or Google is boycotting the wanted results :)

I have a view ("the view"), of type "page" , formatted and styled exactly the way I want it; all is good.

Using the Weight module I have created another view ("the sorter"), also a page, with which to sort "the view".

What I'd like to do is to add 2 tabs, above both views, one leading the "the view's" url and one leading to "the sorter's" url, for easy back and forth transitions from the sorting mechanism to the front-end.

Thanks in advance!

EDIT: Of course I want only the administrators to see those tabs.

For "the view" you should add a menu style default menu tab with View URL: example.com/view/the-view and a parent menu item with URL: example.com/view.
For "the sorter" you should add a menu tab menu item and have the View URL be example.com/view/the-sorter.

This is easier to do than to explain. You might need to fiddling around to get it, but this is the gist of it.


Change OG Group River of News Per Group Basis? Hello i was wondering the best way on how to go about this. I was thinking of creating a text field for my group content type and changing the url and then adding differant block views to urls like-

blog/*
forum/*
etc

Blog will show a blog view and a forum view on forum. I dont really want to mess about with my urls though.

I dont really want to have differant Group Content Types either.

What would be the best if i could have a text select list on the Group Content Type

blog
forum
etc

and the view will change depending on the choice.

Can anyone think of a way of doing this? I think i need to bring in some relatonship for my new text field but itdoesnt seem to be happening for me.

Thanks

heh heh i bloody done it!

Relationships
OG membership: OG membership from Node
(OG membership from node) OG membership: Group Node from OG membership

Filter criteria
(Group node from OG membership) Content: Placetype (= Blog)


Advanced Forum: Hide Form Label How can I hide the label of form in advanced forum?

My content type:forum topic->comment display->comment:label is already set to be hidden

Edit : I realised that it's a form

Log into the Drupal 7 admin dashboard.
Using the top menu bar, locate and click on the Structure option.
From this next page, click on the Content Types link.
On the Content Types page, find the type of content you want to work with. I have been working with Basic Pages so I will stick with that. After locating your desired content type, click on the correct Manage Display link.
From this page you will need to find the filed row  you want to hide and then the Label dropdown. Set the Label field to  to remove the label from the image field.
Once finished, click on the Save button at the bottom.
Clear cache

Or you can use Automatic Nodetitles module

"auto_nodetitle" is a small and efficient module that allows hiding of the content title field in the form. To prevent empty content title fields one can configure it to generate the title by a given pattern.


Where can I find complete documentation of hook_field_info? When I looked into the API documentation page of hook_field_info, it seems to be quite complete. But I could not see the complete details of the return array ingredients.

Why cannot I find the allowed values and detailed descriptions of the following values? Did I miss any documentation page that explain them more in detail?

settings
instance_settings
default_widget
default_formatter

The only documentation you find about those arguments is the one you already linked (hook_field_info()).
The reason that documentation is not very specific is that each field implemented from a module can use any value it needs. For example, the Image field implemented from the Image module uses the following keys for the settings (see image_field_info()):

uri_scheme
default_image

Vice versa, the Decimal field implemented from the Number module uses the following keys (see number_field_info()):

precision
scale
decimal_separator

The default formatter, and the default widget are (respectively) the machine name used for the default formatter, and the machine name of the default widget. The different between formatters, and widgets is that a formatter shows the value of the field, while a widget requests the values necessary for a field.

If you want to see which values are used from a field, you need to check the implementations of the following hooks done from the module implementing the field:

hook_field_info()
hook_field_widget_form()
hook_field_widget_info()
hook_field_formatter_info()


How can I create a simple tab? I'd like to create a tab like the one show in the screenshot for a simple contact address list.

or see this drupal site HERE

I have "contact one," "contact two,"  and "contact three."
I want to put some text under each contact section.

How can I achieve this?

I think you want to use QuickTabs. I am using it on my website (check near the bottom). It seems to be exactly what you want to do. Under each quick tab, you can display nodes, views, blocks or other quick tabs.