# Question
Title: Drupal : How to remove the <p> and <br> tag from content when using syntaxhighlighter
**Used Version 7.14**

I am using syntaxhighlighter for my website. But when I insert some code samples it always producing output with more `<p>` and `<br>` also content in single line as well .

I am done just copy paste the code from zend studio editor inside the syntaxhighlighter tag

I've searched over many forums and druapl site itself, but nothing works for me. Please advise me on this

See the picture below for more

# Answer
> 1 votes
I can't answer this 100% but my first hunch was "hrm, filter ordering" and look, the project page draws your attention to:

> Very important!!!: ordered the input format filters as follow:
>
> * HTML filter or Wysiwyg filter or whatever HTML filters you use. They must come before.
> * Syntax highlighter. This come after any and all filters that can modify content input.
> * Line break converter. This must be after, If you see \<br/\> at the end of every line in your output, then you know what's wrong.

---
Tags: input-formats
---


# Question
Title: How does Drupal determine the context in which to display the admin theme?
One of the great things about Drupal 7 is the inclusion of an administration theme, Seven.

How does Drupal determine whether to display the administration theme or the site's theme?
Is it path-based (everything under /admin), or something else?

# Answer
> 4 votes
There is now a hook for this: hook\_admin\_paths(). As usual, the default configuration is in system\_admin\_paths() but there are many other implementations in core, search for \_admin\_paths.

# Answer
> 1 votes
Here is an example for using hook\_admin\_paths to display the advance help + user login pages in the admin theme.

```
/**
 * Implement hook_admin_paths(),
 * to define which paths will be displayed in the admin theme.
 */
function objet_admin_paths() {
  $paths = array(
    'help*' => TRUE, // the advanced help module
    'user*' => TRUE, // User login screens
  );

  return $paths;
}

```

---
Tags: 7
---


title: Menu to be displayed as jCarousel

text:
# Question
Title: Menu to be displayed as jCarousel
Is there a method to show a menu as a jCarousel? My requirement is to show each menu item as element of a jCarousel.

# Answer
> 1 votes
**Short:** If your "menu" was actually a taxonomy tree, it would almost trivial to do what you want, and much more, as most contrib modules operate on a entity basis.

**Longer:** This answer will mostly be applicable to someone that does not already have a menu structure created, so for some people, it will be of little use.

While displaying a Drupal menu in essentially any way is certainly possible, the menu system in Drupal is rather aged compared to a lot of other functionality.

Generally, whenever you wanna do fancy stuff, I would recommend you avoid the menu system completely. You can even disable it completely in D7. Yes, this type of setup will require more work initially, but is *a lot* more flexible.

# Answer
> 0 votes
I recommend using the Views and Views Slideshow modules.

Using Views, create a View that lists the titles (or whatever fields you want) of whatever entities you're interested in, and displays them as links. This simulates a menu. Then choose "slideshow" as the display format, and configure to your heart's content.

It won't have hierarchy unless you have grouping fields to use, but a slideshow can't make much use of hierarchy anyway.

---
Tags: javascript
---


# Question
Title: Count only published nodes with taxonomy term
I have implemented a view according to this question: Views and node count for taxonomy terms

But the view also counts the unpublished content.

How can I modify the view to count only published content?

# Answer
You need to add a **Filter Criteria** on the view, and choose `Content: Published` as the criteria, and `Yes` as the value. This also needs to use the `(node)` relationship.

See `/* Filter criterion: Content: Published */` on this code. Or import it and look under "Filter Criteria"

```
$view = new view;
$view->name = 'Taxtest';
$view->description = 'Displays node count values for terms';
$view->tag = '';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'term_node_count';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '100';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'name' => 'name',
  'nid' => 'nid',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'nid' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* Relationship: Taxonomy term: Content with term */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'taxonomy_index';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
$handler->display->display_options['relationships']['nid']['required'] = 0;
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = 1;
/* Field: COUNT(Content: Nid) */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['relationship'] = 'nid';
$handler->display->display_options['fields']['nid']['group_type'] = 'count';
$handler->display->display_options['fields']['nid']['label'] = 'Count';
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['relationship'] = 'nid';
$handler->display->display_options['filters']['status']['value'] = '1';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');

```
> 2 votes

---
Tags: 7, views
---


# Question
Title: How do I get inline tags to wrap nicely?
Inline tags are presented as a series of `<div>`s, with no whitespace in the HTML between them. These elements are styled `display:inline`, the result of which is an unbreakable string. When you have enough tags this breaks layout. What you want is tags to word-wrap around, but they don't.

The only way I can see to achieve this is by hacking core to insert a space after the field-item items' `<div>`s (or after the content before the closing `</div>`.

Is there another way? Perhaps a way for a theme to override the formatter function?

# Answer
Try using `display: inline-block` instead. It gives you the functionality of an inline element, but you can apply margins and padding to it just like a block-level element.
> 3 votes

# Answer
I typically either make them `inline-block` or make my own `theme_field` for my theme. I would say I tend to do the latter more. Typically, I just copy the default implementation into my theme, rename, and make minor adjustments. More often than not, though, I am already making formatters for specific fields.
> 2 votes

---
Tags: 7, theming
---


title: multilingual blocks in drupal6

text:
# Question
Title: multilingual blocks in drupal6
I use drupal 6 . I have some menus in the site. I 'm going to add other language support to my website. I know how to create multilingual content (nodes) but I don't know how to do it with menus like navigation menus.

would you help me?

# Answer
> 1 votes
If you install the Internationalization suite of modules, you can enable the Internationalization blocks module (called Translate Blocks).

This will allow you to assign a language (or languages) to each block.

This way, you can create a menu for each language and then assign a language to each menu block.

* Note that there is also a Translate Menu module in the Internationalization suite. This module allows you to create one menu with items of multiple languages. However, this can get confusing and complicated very fast and is often difficult to maintain over time. For this reason, most people create separate menus for each language as described above.

---
Tags: i18n-l10n, blocks
---


# Question
Title: How to override  ad_adapi() in custom module
Currently, in my custom module that depends from the Advertisement module, I have permissions case, and I want to add `statics_increament` in my custom module.

How can I override `ad_adapi()`?

# Answer
As the Advertisement module invokes that hook using `module_invoke_all('adapi', 'permissions')`, and it doesn't use `drupal_alter('adapi')`, your module could override that implementation of `hook_adapi()` using code similar to the following one. (I assume the short name of your custom module is "custom\_module"; change it to the short name you are using for your module.)

```
function custom_module_adapi($op, $node = NULL) {
  switch ($op) {
    case 'permissions':
      return array(
        'access statistics' => TRUE,
        'access click history' => TRUE,
        'access activity log' => TRUE,
        'set status as pending' => FALSE,
        'set status as denied' => FALSE,
        'set status from pending to approved' => FALSE,
        'set status from pending to denied' => FALSE,
        'set status from approved to active' => TRUE,
        'set status from approved to offline' => TRUE,
        'set status from active to offline' => TRUE,
        'set status from active to expired' => FALSE,
        'set status from offline to active' => TRUE,
        'set status from offline to expired' => FALSE,
        // Add your permissions.
      );
      break;
  }
}

function custom_module_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'adapi') {
    // Move custom_module_module_adapi() to the end of the list. module_implements()
    // iterates through $implementations with a foreach loop which PHP iterates
    // in the order that the items were added, so to move an item to the end of
    // the array, we remove it and then add it.
    $group = $implementations['custom_module'];
    unset($implementations['custom_module']);
    $implementations['custom_module'] = $group;
  }
}

```
* `custom_module_adapi()` is completely overriding the values returned from `ad_adapi()`; for this reason, it cannot simply add the extra values it needs.
* The code I wrote is a kind of hack; the correct way would be for the Advertisement module to use `drupal_alter()` to allow third-party modules to override the values set from other modules. The code I wrote works, but you need to keep update the code for `custom_module_adapi()` with the code used in `ad_adapi()`, in the case it is changes.
* Only the branch 7.x-1 has `ad_adapi()`; the branch 7.x-2 doesn't have that function anymore. If you are planning to use that branch, the code for your custom module should be changed.
> 0 votes

---
Tags: 7
---


# Question
Title: Meta tags aren't saved with all content types
I use the module Meta Tags for adding meta data to my nodes. And it works like a charm. It's super easy to add meta tages like `title`, `keywords`, `description`,... even our IT-noob marketing team can do so. It's awesome.

However, not all content types seems to be able to save those meta data. I've got 12 content types and 3 of them don't display the meta data. Although I add them like on the other nodes...

Here is the source code of a node without any meta:

And here with meta:

So correct me if I'm wrong, but I don't see any meta data in the first example.

Strange part, all the data is present in the database (table `metatag`), so all nodes does save the meta data, but for some reason, some content types aren't displaying the meta data.

What could be the cause of this "bug". Could it be something like hiding certain content in the template files since they all have a separate `.tpl.php` file? Or what other causes are you thinking of?

# Answer
There is an issue with the module.

Try the following code in node.tpl.php.

```
render($content['metatags']);

```

Alternatively, try with the following code in page.tpl.php.

```
print render($page['content']['metatags']);

```
> 1 votes

---
Tags: 7, meta-tags
---


# Question
Title: Canonical URL for Front Page - without path
I've been looking for a solution to the Front Page URL issue that meets the following criteria.

* Allows me to keep the Canonical and Description Tags from Meta Tags Quick on Views sub-pages.
* Allows web client users to change the meta description on the front page through the Meta Tags module.

I use both the Meta Tags and Meta Tags Quick modules for views tagging and automation on standard nodes. Unfortunately I haven't been able to set the /welcome page canonical URL to a forced "http://www.website.com/". I continue to get "http://www.website.com/welcome" for the front page.

I've tried removing the path alias. I've tried setting path specific meta tags with the 'quick' module. I've input the details into the standard Meta Tags module under global front page.

Maybe there is some combination that I'm missing. Any ideas?

Additional: I've been using the Redirect Module on the site - if that matters.

Solution: Alright - after extensive poking around the issue was that I added Canonical URLs as a \[current-page:url:absolute\] to the GLOBAL settings rather than the Content.

This meant that the GLOBAL Front Page override was overridden by the other elements.

Worked for me, for now. Apparently I can't post the solution that I found with my team because I'm a new user. I don't plan to come back this week and will forget to publish a fix if I don't put it here. Get used to it.

# Answer
Alright - after extensive poking around the issue was that I added Canonical URLs as a \[current-page:url:absolute\] to the GLOBAL settings rather than the Content.

This meant that the GLOBAL Front Page override was overridden by the other elements.
> 1 votes

---
Tags: 7, views, path-aliases, meta-tags
---


# Question
Title: How to add a new user permission "Translate own nodes" ?
Looking for this Translation own nodes module but for Drupal 7.

The goal is to create a new permission to "Translate own nodes".

# Answer
> 1 votes
The basic method followed by that module should work (custom access callback + hook\_menu\_alter), but the code would need updating for D7.

From a quick scan of the code (so there may be other things that need updating) hook\_perm is now hook\_permission and hook\_nodeapi has been replaced by serveral hooks (in this case only the 'prepare' op is used, so hook\_node\_prepare is the only one required here).

---
Tags: 7, i18n-l10n
---


# Question
Title: How to find the values that have changed in a form submission?
How can I tell what values have changed in a validate hook of a form submission?

# Answer
What I have done is to see if the value in `$form_state['values']` is different from the `#default_value` in `$form`, like so:

```
if ( $form_state['values']['variable'] <> $form['variable']['#default_value'] ) { ... }

```
> 6 votes

# Answer
Something that i do in my forms is set defaults.

Take:

```
    isset($form_state['values']['datacenter']) ?
    $selected = $form_state['values']['datacenter'] : $selected = 0;

$form['grid']['datacenter'] = array(
    '#title'            => 'Datacenter',
    '#type'             => 'radios',
    '#default_value'    => $selected,
    '#required'         => true,
    '#options'          => array(),
);

```

what you could do is check your `#default_value` to see if its not 0 in this case. so in your `MYMODULE_form_validate($form, &$form_state)` function, simply grab your `$form_state` values and if its not zero in this case, call some other function or whatever you want to do.
> 4 votes

---
Tags: forms
---


title: Unable to Edit <title> in Product Pages

text:
# Question
Title: Unable to Edit <title> in Product Pages
I am unable to edit the tag on any of my product pages, however, I am able to edit on all other pages. The Page Title option or slot is not even shown on the edit of my products. I have the Page Title module (6.x-2.5) uploaded and enabled. Any ideas?

# Answer
> 0 votes
Page Title is enabled (or disabled) on a per content-type basis.

You should be able to go to http://mysite.com/admin/content/types/product and enable it using the checkbox in the following fieldset:

---
Tags: meta-tags
---


title: Using Realnames in other places

text:
# Question
Title: Using Realnames in other places
In Drupal Commons, we're using the Realnames module. Is there a way to extend this module's information to other search box fields?

For example in the Organic Groups invite (/og/users/??/invite), could my users search for other users by the user's first or last name? That is, in the form **og\_invite\_link\_invite\_page\_form**'s first field (edit-invitees), how could I search on an individual's Given Name (first name) or Family Name (last name)?

This addition provided what I needed. Basically, I needed to override the $form\['invitees'\] by using and slighly modifying og\_username\_helper.module ( http://drupal.org/project/og\_username\_helper ).

```
 74     if ($form['#id'] == 'og-invite-link-invite-page-form') {
 75       // print 'in';
 76       // print_r($form['invitees']);
 77
 78       $form['invitees'] = array(
 79           '#type' => 'textfield',
 80           '#description' => t('Lookup a username and add it to the list below.'),
 81           '#autocomplete_path' => 'og/username_helper/autocomplete',
 82           '#size' => 40,
 83           '#maxlength' => 60,
 84           '#weight' => -2,
 85           '#access' => $helper_access,
 86           );
 87
 88       return $form;
 89     }
 90

```

# Answer
> 1 votes
I've packaged this up into a module to extend the og\_username\_helper.

```
 58 /**
 59  * Extends og_username_helper to Groups Invite Members tab
 60  */
 61 function soc_searchtweak_form_alter(&$form, $form_state, $form_id) {
 62
 63   $form_changes = array();
 64   $form_changes['og-invite-link-invite-page-form']='invitees';
 65   $form_changes['commons-profile-friend-search-form']='search_text';
 66
 67
 68   foreach ($form_changes as $form_id=>$field_id) {
 69
 70
 71     if ($form['#id'] == $form_id) {
 72       $form[$field_id] = array(
 73           '#type' => 'textfield',
 74           '#description' => t('Lookup a username and add it to the list below.'),
 75           '#autocomplete_path' => 'og/username_helper/autocomplete',
 76           '#size' => 40,
 77           '#maxlength' => 60,
 78           '#weight' => -2,
 79           '#access' => $helper_access,
 80           );
 81
 82       return $form;
 83     }
 84
 85   }
 86
 87
 88 }

```

The module.info file puts og\_username\_helper as a dependency.

```
1 name = Search Tweak
2 description = Extends og_uesrname_helper in various places
3 core = 6.x
4
5
6 dependencies[] = og_username_helper

```

---
Tags: organic-groups
---


title: Assigning a role in code isn't working

text:
# Question
Title: Assigning a role in code isn't working
I want to add a user to a role when a checkbox on the profile has been checked. It's printing the dpm() message but not adding the user to the role. What am I missing.

```
function mycustom_form_user_profile_form_alter(&$form, $form_state, $form_id) {
  $form['#validate'][] = '_user_profile_validate';
  ...
}

function _user_profile_validate(&$form, &$form_state) {
  if (($form_state['values']['field_restricted']['und'][0]['value']) == 1) {
    dpm('role added');
    global $user;
    user_multiple_role_edit(array($user->uid), 'add_role', 6);
  }
}

```

# Answer
I tried with db\_insert() and got the same result. Turns out that when the profile form is saved it will overwrite the roles again, which makes sense, since Drupal thinks that the user has changed the roles on the profile form ...

So I just added the role to the form\_state array and it worked:

```
function _user_profile_validate(&$form, &$form_state) {
  if (($form_state['values']['field_restricted']['und'][0]['value']) == 1) {
    if (!in_array('6', $form_state['values']['roles'])){
      $form_state['values']['roles']['6'] = 6;
    }
  }
  else {
    if (in_array('restricted', $form_state['user']->roles)){
      $form_state['values']['roles']['6'] =  0;
    }
  }
}

```

Thanks for all the help!!!
> 1 votes

# Answer
Your code seems fine. Maybe you could add an additional condition to see if your role argument is proper:

```
$role_name = 'Role to add'; // The name of the role to add.
  if ($role = user_role_load_by_name($role_name)) {
    user_multiple_role_edit(array($user->uid), 'add_role', $role->rid);
  }

```

I would try adding this condition to make sure all arguments are as intended. Maybe 6 is not a valid index? With this extra condition you will be sure.

Hope this helps, cheers!
> 1 votes

---
Tags: 7, users
---


# Question
Title: How do I calculate the resource requirements for using Solr?
I want to use Apache Solr for faceted navigation of my D6 site(s), but I'm unsure of the resource requirements for it. How do I check if my VPS can cope with implementing it?

# Answer
> 3 votes
This is not the most complete answer but no one else has stepped up so hopefully this can be somewhat helpful.

I would say that the biggest potential issues on a box that size would be running out of memory and disk space. You can allocate memory to your java vm to mitigate potential memory issues. Solr is under load when indexing and retrieving search results (obviously). You can mitigate the indexing load by indexing in small batches. Though in terms of memory footprint if you are substituting solr with normal Drupal search your load on apache/mysql will be greatly reduced.

I would say that I've run multiple solr instances with a higher load than you are describing on a 1GB VPS.

You may get a more detailed answer if you go to ServerFault or the Solr mailing list and share the solrconfig.xml and schema.xml files from the ApacheSolr module.

---
Tags: 6, search
---


title: Adjusting the content size of my theme

text:
# Question
Title: Adjusting the content size of my theme
I have not messed around with themes much yet, but I would really like to be able to adjust the relative width of different blocks in my Bartik theme. As you can see in the screenshot, my panel is not quite big enough to display both views without overlapping, and there is plenty of extra space on the sides.

How does one change the relative widths assigned to each block? Also, when I start making changes like this, would it be wise to make my own copy of Bartik and store it elsewhere?

# Answer
This is something you would most likely want to adjust using your style.css file and an inspector program (such as DOM Inspector for Firefox) in the browser.

Another way to do it would be to use a grid-based theme like Omega that lets you choose how many columns wide to make zones and regions. Using Omega Tools you can do that directly in the Appearance admin configuration UI.
> 1 votes

---
Tags: theming
---


title: custom node status

text:
# Question
Title: custom node status
In `admin/content` there is the "status" filter which by default gives us:

```
any
published
not published
promoted
not promoted
sticky
not sticky

```

I can see that these map directly to the `node` table in the database:

```
mysql> select nid, status, promote, sticky from node;
+-----+--------+---------+--------+
| nid | status | promote | sticky |
+-----+--------+---------+--------+
|   1 |      0 |       0 |      0 |
+-----+--------+---------+--------+

```

Is there a way to add a 4th boolean column? For example `important` so in the filter I get `important` and `not important` and also in the Publishing options of `node/1/edit` I also get a checkbox "Important node".

I've seen the http://drupal.org/project/flag project but I want something simpler which will apply this information on the `node` table. Is it possible?

# Answer
> 4 votes
I think the Custom Publishing Options module is exactly designed for your needs.

> This module allows you to create custom publishing options for nodes. It allows you to add to the default options of Publish, Promote to Front Page, and Sticky. It also ingrates with views to allow you add as a field, sort and filter by, your custom options.
>
> It now allows each of the different options to be shown only on selected node types, as well as integration with Rules/Actions, and permissions for each option type.

# Answer
> 4 votes
Flag would probably be the most 'Drupal' way to do it without writing your own module, which incidentally would be the only way to modify the node table without a significant manual hack. Although I'm pretty sure you wouldn't want to do that as it might affect the way that other parts of Drupal work.

---
Tags: 7, nodes
---


# Question
Title: How do I add unique page titles and meta titles to paginated views pages?
I have overridden the taxonomy term pages with a view, and I want to be able to set the page title, both visible and meta, with unique titles for each page within the pager for SEO purposes. I am hoping the solution resides in a module, or in a view setting (and not on a template basis).

Do you have any suggestion?

# Answer
There are actually two modules:

* the Meta tags module that is used to add meta tags to any pages

> The Meta tags module allows you to automatically provide structured metadata about your website. In the context of search engine optimization, when people refer to meta tags, they are usually referring to the meta description tag and the meta keywords tag that may help improve the rankings and display of your site in search engine results.
* the Page Title module that is used to set the title visible with the `<title>` tag

> This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content's title.
* the Title Overrides module

> Title Overrides is a module to provide title overrides for any page in as simple as an interface as possible. This module differs from the Page Title module in that this overrides both the `<title>` meta tag as well as the `<h1>` tag. You also have the option of entirely removing the page title from any page, which will remove the `<h1>` tags as well as remove the piping from the meta title. This improves search engine optimization for pages that have been overridden.

As far as I recall, there were some problems using the Meta tags module to set meta tags for views, but it can be they have been resolved, now.

The Title Overrides module seems the one you are looking for, as it overrides the content's title for any page.
> 1 votes

---
Tags: views, taxonomy-terms, 7
---


title: Comment only once per node

text:
# Question
Title: Comment only once per node
I'm trying to get my users to post only once on each Product node... I'm kind of new to hooks and I'm not sure what else should I use for this.

What is the drupal way to do this?

# Answer
> 2 votes
You can use the Comment limit module.

> Limits how many comments a user may post on a node. Adjustable on a per node type basis.
>
> This module can be handy for instance when comments are used as "Reviews" and "Ratings" for products and a user may only review and rate a product once.

---
Tags: comments, forms
---


title: cache a rest server index request

text:
# Question
Title: cache a rest server index request
I created one custom module for rest server, i created own resources and i want to be able to cache index request, for return a 304 with using http request if - headers.

I cannot find information on how to do it.

# Answer
I did it setting my own headers (cache-control, last-modified, etag, expires), and setting rules for delete cache.
> 0 votes

---
Tags: caching, services, 8
---


title: Displaying a menu's child links

text:
# Question
Title: Displaying a menu's child links
It seems that, by default, Omega, and other themes do not render child links.

I have tried various modules (e.g. Superfish, and Megamenu), but they do not offer a structure that allows me to theme to the design I am after.

I found this page, but it does not seem to use `theme_links()`.

Is there a simple way to enable all my menu links, and still be able to hook into it before they are rendered?

# Answer
The answer lies in how and where menu\_tree\_page\_data is being called.

For the navigation, Drupal will call \*menu\_tree\_page\_data\* via menu\_navigation\_links which will only return a single level of links. You can follow this function up to menu\_main\_menu and then template\_preprocess\_page before it (which is how it ends up as a variable in page.tpl.php)

However, if you insert a menu as a block \*menu\_tree\_page\_data\* is called by menu\_tree (which calls menu\_tree\_output immediately after which does some additional work to the array for the final markup.) After both have run you have your whole menu tree available as an array which I then ran through some custom PHP code to loop through the array and render it into an HTML list.

p.s. I also did not use any of Drupal's default menus. I created my own because I needed control of how my mark up was built (and because I had trouble getting control of the 'links' hook to use with theme\_menu\_link.) I defined my own theme hook ("THE\_MENU\_NAME") corresponding to my menu name and also my own theme template which is where I did all my markup building before rendering.

theme('links\__system\_main\_menu', array('links' =\> $main\_menu, 'attributes' =\> array('id' =\> 'main-menu', 'class' =\> array('links', 'inline', 'clearfix', 'main-menu')), 'heading' =\> array('text' =\> t('Main menu'),'level' =\> 'h2','class' =\> array('element-invisible'))));

```
theme('THE_MENU_NAME', array('menu_tree' => $menu_tree));

```

I hope this helps some people out there.
> 0 votes

# Answer
Go to your parent menu item, edit it and click on the 'Show as expanded' checkbox. Now all the children menu items should be visible from the top level.
> 2 votes

---
Tags: 7, routes
---


title: Print the WHOLE menu?

text:
# Question
Title: Print the WHOLE menu?
Is there a way to print out an array of the entirety of a menu in Drupal 7?

For example, I have access controls in place so that a user gets a role after they take a quiz, which then allows them to see the next quiz. So until they pass quiz #1, their menu will not show them any evidence of quiz #2's existence.

What I want to do is print out the titles of ALL menu items, regardless of whether the user has access to the associated nodes or not. I plan to rewrite the menu to make the permitted items links, while the others appear greyed out until the user gains access to them.

I have not been able to find any modules, and simply doing this:

```
print_r(menu_navigation_links('menu-program-menu'));

```

only shows the items that the user has permission to view.

Is there a module already that does this, that I just haven't been able to find? Does a query have to be made directly to the database or is there a way to do this with more finesse?

# Answer
> 1 votes
Besides writing custom database queries you might be able to use functions listed on the Menu API page. For example menu\_load\_links() loads all the links of the specified menu. menu\_link\_load() can be used to get additional (including access) information besides the general link data (thanks, beth, for pointing this out!). You could also use the code of the listed functions to create your own similar functions without the access controls.

# Answer
> 1 votes
What you can do is to select corresponding titles from the database directly:

```
$sql = "SELECT l.link_title FROM {menu_links} l WHERE l.menu_name = :menu_name ";
$result = db_query($sql, array(':menu_name' => 'menu-program-menu'));
foreach($result as $object) {
    print $object->link_title;
}

```

---
Tags: 7, routes, users
---


# Question
Title: Autopopulate EntityReference field using rules?
I'd like to have an EntityReference field be autopopulated by the node that was just navigated from.

So the workflow would be:

User views page for Business A -\> User clicks review link -\> User is presented with review form, & EntityReference field is automatically populated with the name/id of Business A.

What I don't know is which action to designate to tell Rules to do this. I have Event set to "before saving content," and Elements set to "Entity has field, Parameter: Entity: \[node\], Field: field\_venue\_reference." These seem like the correct settings for these portions from what I have read, but since I'm new to Rules, I'm not completely sure of that either. Any suggestions?

# Answer
You want the Entity Reference Prepopulate module. It's very similar to the Node Reference URL module but the maintainer of that module is stubborn and sticking to only referencing Nodes and not Entities.

Rules has always had a hard time with prepopulating reference fields so please don't go that route. You can combine Rules and ERP by using Rules to populate other fields and ERP to handle the referencing.

Everything is URL based so you must setup your links appropriately. The structure is node/add/article?\[field\_ref\]=\[id\] So you could have node/add/review?field\_business\_ref=457

your link to the form could look something like `l('add review', 'node/add/review?field_business_ref='. $node->id)`
> 4 votes

# Answer
If you have 2 node types Bussines and Review, and you only want to add the reference, than Node Reference URL might be the solution for you. Here is a greate tutorial for this module

http://mustardseedmedia.com/podcast/episode37
> 0 votes

---
Tags: rules, entities
---


# Question
Title: Commerce View + Multiple products on product_reference field
i'm having troubles at making a custom view of some products i have in my commerce.

Here is a simple example: I have 1 T-shirt, with 4 colors. Each color has it's own price (they are all different), and it's own images (4 images per t-shirt).

Now, i need something like this

And my real design is this one

I just seen, that Views can't be used since there is now way to replicate the default node functionality, since every field won't refresh (remember there are 4 variables...prices and images)

I can use a "custom node-type.tpl.php", and make some custom "field-field-name.tpl.php" too, to make my design.......BUT how do i add an image gallery per product???

hope it's clear, i do not speak english. thanks for everthing.

# Answer
If anyone need an image gallery for commerce, and you have a node referencing multiple product which have multiple images, Image zoom is the correct module.
> 1 votes

---
Tags: commerce
---


# Question
Title: How do I make form_set_error() affect the submitted form only?
I have a couple of different forms on one page; each has a 'name' field.

Sensibly, on submission drupal processes the submitted form, but in what seems a completely barmy way of doing things, form\_set\_error() just takes a field name, and appears to have no knowledge of which form was submitted.

So if the name field is invalid on the submitted form, it gets marked as invalid on all the other forms that use a field called 'name'.

Does this mean that every field needs a unique field name, e.g. name-somemodule1 and name-somemod2? This will break user convenience (browser probably knows what to pre-fill for 'name').

Sure I've missed something, but have read a lot of FAPI pages and code comments and am still confused.

In the screenshot below, you'll see 2 forms. The one on the left is the submitted one, with 'invalid-name' in a field called 'name'. The one on the right is **not** submitted (can only physically click one submit button at once!) and yet it's 'name' field (with 'admin' in it) is also marked invalid.

These are entirely separate forms.

Here's my modules' code (email field omitted, some attrs omitted just to reduce post size)

```
function mymod_contact_form() {
  $form['comment'] = array(
    '#title'         => t('Enter query'),
    '#default_value' => '',
    '#type'          => 'textarea',
  );

  $form['name'] = array(
    '#title'         => t('Enter name'),
    '#default_value' => '',
    '#type'          => 'textfield',
  );

  $form['submit'] = array(
    '#type'  => 'submit',
    '#value' => 'Send',
  );

  return $form;
}

function mymod_contact_form_validate($form, &$form_state) {
  $name = trim($form_state['values']['name']);
  if (strpos($name,' ') === FALSE) {
    form_set_error('name', t('Please enter your full name'));
  }
}

function mymod_contact_form_submit($form, &$form_state) {
  $vals = $form_state['values'];
  // …
}

```

# Answer
There is definitely a limitation in Drupal core that is causing form fields with with the same name to be styled as "error" even through the validation error happened on a different form that was submitted on the same page. Looking at the code for Drupal version 6,7,8 (as of now) - they all have this limitation. The good news is that the patch I put together (for Drupal 6) to fix this problem is fairly minimal and it involves using the form\_id to properly scope the form element with the validation error. I've haven't done much testing with it, so use it at your own risk. The changes required for Drupal 7 should be similar.

```
diff --git a/includes/form.inc b/includes/form.inc
index 1529c19..4052133 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -798,29 +798,41 @@ function form_execute_handlers($type, &$form, &$form_state) {
  *   The error message to present to the user.
  * @param $reset
  *   Reset the form errors static cache.
+ * @param $scoped
+ *   Returns the errors scoped with the form_id
  * @return
  *   Never use the return value of this function, use form_get_errors and
  *   form_get_error instead.
  */
-function form_set_error($name = NULL, $message = '', $reset = FALSE) {
+function form_set_error($name = NULL, $message = '', $reset = FALSE,$scoped = FALSE) {
   static $form = array();
+  static $form_scoped = array();
   if ($reset) {
     $form = array();
+    $form_scoped = array();
   }
   if (isset($name) && !isset($form[$name])) {
     $form[$name] = $message;
+    if(isset($_POST['form_id'])) {
+      $name = $_POST['form_id'] . "::" . $name; // Scope it based on form_id
+    }
+    $form_scoped[$name] = $message;
     if ($message) {
       drupal_set_message($message, 'error');
     }
   }
-  return $form;
+  if($scoped) return $form_scoped;
+  else return $form;
 }

 /**
  * Return an associative array of all errors.
+ *
+ * * @param $scoped
+ *   Returns the errors scoped with the form_id
  */
-function form_get_errors() {
-  $form = form_set_error();
+function form_get_errors($scoped = FALSE) {
+  $form = form_set_error(NULL,'',FALSE,$scoped);
   if (!empty($form)) {
     return $form;
   }
@@ -828,16 +840,29 @@ function form_get_errors() {

 /**
  * Return the error message filed against the form with the specified name.
- */
-function form_get_error($element) {
-  $form = form_set_error();
-  $key = $element['#parents'][0];
-  if (isset($form[$key])) {
-    return $form[$key];
-  }
-  $key = implode('][', $element['#parents']);
-  if (isset($form[$key])) {
-    return $form[$key];
+ *
+ * * @param $scoped
+ *   Returns the error scoped with the form_id
+ */
+function form_get_error($element,$scoped = FALSE) {
+  if($scoped && isset($element['#form_id'])) {
+    $form_id = $element['#form_id']; // Try to make the error form specific
+  }
+  $form = form_set_error(NULL,'',FALSE,$scoped);
+
+  for($i=0;$i<2;$i++) {
+    if($i==0) $key = $element['#parents'][0];
+    else $key = implode('][', $element['#parents']);
+
+    if(isset($form_id)) {
+      $key0 = "$form_id::$key"; // Provide the scope based on form_id
+      if(isset($form[$key0])) {
+        return $form[$key0];
+      }
+    }
+    if (isset($form[$key])) {
+      return $form[$key]; // If form_id not found then try without it
+    }
   }
 }

@@ -896,6 +921,7 @@ function form_builder($form_id, $form, &$form_state) {
   $count = 0;
   foreach (element_children($form) as $key) {
     $form[$key]['#post'] = $form['#post'];
+    $form[$key]['#form_id'] = $form_id;
     $form[$key]['#programmed'] = $form['#programmed'];
     // Don't squash an existing tree value.
     if (!isset($form[$key]['#tree'])) {
@@ -2246,7 +2272,7 @@ function _form_set_class(&$element, $class = array()) {
   if ($element['#required']) {
     $class[] = 'required';
   }
-  if (form_get_error($element)) {
+  if (form_get_error($element,TRUE)) {
     $class[] = 'error';
   }
   if (isset($element['#attributes']['class'])) {

```
> 5 votes

# Answer
Now, `form_set_error` is indeed a nasty piece of work and I take the full blame for not fixing it in D7 -- but then again, you have `drupal_static`. Just call `drupal_static_reset('form_set_error');` some time between putting out the two forms and be done.

Edit: as the comments point out this is not so simple because we first assemble the page array and then render it and only during render time we add the errors to the form fields. So then you need a wrapper around `drupal_get_form` which calls it, records the errors somewhere (a global or another `drupal_static`), resets the errors, adds a `#pre_render` callback to the top level of the returned form structure. This callback needs to read the errors from our storage and set it back into the `form_set_error` `drupal_static`. Yuck! This perhaps would be a nice contributed module.
> 1 votes

---
Tags: 7, forms
---


# Question
Title: Displaying a list of image thumbnails, with click-through
So, a few days ago I asked this question, Drupal 7 Site for Displaying PPT or JPG. Since that time I have been studying up on Drupal 7 and learning more about what I REALLY want.

Here's what I am trying to do:

1. Upload a bunch of images (around 150)
2. Have a number of pages which list images including a thumbnail and comments. (These pages are roughly 'image galleries', I think)
3. Let users browse each of the 'galleries'/lists, and click through on the ones they want to view in detail. Also, users can add comments at this point.
4. If the user saves a comment or clicks a back button, they return to the gallery/list

So, I think I need to create a new content type for the images, including comments. Then a View, which displays as a list. Does this sound right?

Also, what's the best way to create each of the image nodes? Do I need to use the Insert module? And upload the images one by one?

Any pointers much appreciated!

# Answer
Creating a new *Image* content type is a good way to approach this. Views can certainly display the content as a list or a gallery-- or some combination of both-- but you may want to think about how you want to display the content in the gallery.

Comments are handled by Drupal out-of-the-box so I don't think you have much to worry about with regard to them.

You do not need to use the Insert module if you're just going to be uploading an image file. If you're only going to be adding 150 images once, I would just create the image nodes one-by-one. If you anticipate having to add lots of images regularly, you should post a separate question asking for a solution to that.

Here are some resources to get you started.

First, there's a screencast about building a gallery in Views. Although this is for Drupal 6, and a fair number of things have changed in Drupal 7, the basic principles are the same.

Second, there are some helper modules which can give you pop-up and gallery-type effects without much work. Two of the more popular, well-supported ones are:

Either can be used on its own or with Views.
> 1 votes

---
Tags: media
---


title: Programmatically create a organic group

text:
# Question
Title: Programmatically create a organic group
How would you programmatically create an OG group? I have tried `node_save()` but to no joy.

# Answer
> 5 votes
It's simpler than attaching node as group post:

```
  <?php
  global $user;
  $node = new stdClass();
  $node->type = 'group'; // Change this to group node type name.
  $node->uid = $user->uid;
  $node->title = t('Title'); // Change title generation
  $node->body = t('Body'); // Change body generation
  $node->og_description = t('Group description'); // Change group description generation
  $node->og_selective = OG_CLOSED;
  $node->og_register = OG_REGISTRATION_NEVER;
  $node->og_directory = OG_DIRECTORY_CHOOSE_FALSE;
  $node->og_private = 0;
  node_save($node);
  og_insert_group($node);
  og_save_subscription($node->nid, $node->uid, array('is_active' => 1, 'is_admin' => 1));

```

(ofcourse you also need to check the return values from alle the three functions)

# Answer
> 1 votes
I don't really understand the question, but I created a lot of groups using the Mass Create module.

# Answer
> 1 votes
I was in the same struggle, but I realized that to create a new OG group programatically, the Rules module could be the key.

If you look for the right trigger and conditions, the first action would be "Entities \> Create a new entity \>OG group.

You can use the Rules scheduler to do the timing, if necessary.

---
Tags: 6, organic-groups
---


# Question
Title: Can node_url be accessed in page.tpl.php?
Calling `debug($node)` in page.tpl.php seems to show that the node object is not fully populated at this stage.

I would like to access node\_url in my page template so that I can add certain CSS classes for some nodes without having to use the nid. Is there maybe a way to access a more fully populated node object in `template_preprocess_page()`?

# Answer
> 5 votes
You could use the `drupal_get_path_alias()` function along with the node's `nid` to get the URL alias of the node without having to load the object:

```
$url = drupal_get_path_alias("node/$node->nid");

```

If you want the fully loaded node object though use `node_load()`:

```
$node = node_load($node->nid);

```

Memory fails me as to whether `node_url` is added to the node object in a `hook_node_load()` implementation or as part of a theme preprocess so I'm not 100% sure it's implicitly available after you call `node_load()`...if it's not just use the first example which will work.

**UPDATE**

On inspecting the node module the `node_url` member comes from `template_preprocess_node` so while `node_load()` will give you the fully loaded node, I don't think it's going to be useful in this case.

In fact looking at `node.tpl.php` and `template_preprocess_node`, `node_url` isn't added to the node object at any point so you wouldn't normally access it with `$node->node_url` but instead `$node_url`. That variable is available by default in `node.tpl.php` but not `page.tpl.php` so you'll have to get it another way (i.e. first example above).

# Answer
> 1 votes
$url = drupal\_get\_path\_alias("node/$node-\>nid");

The above will return the URL path, but NOT the ?q= if you are not using clean URLS. Just thought I'd mention that.

---
Tags: 7, theming
---


# Question
Title: Why my hook_filter not work in Drupal 6?
I'm having a hard time trying to make my hook\_filter work on Drupal 6.

Here's my filter function.

```
function arb_question_filter($op, $delta = 0, $format = -1, $text = '') {

  drupal_set_message($op);

  switch($op){

  case 'list':
    return array(t('My filter name here'));

  case 'description':
    return t('Description my filter here');

  case 'settings':
    break;

  case 'no cache':
    return false;

  case 'prepare':
    return $text;

  case 'process':
    return preg_replace("|\[support!\]|i", 'hello world', $text);

  default:
    return $text;
  }
}

```

I can see my filter name on the filter option below the content textarea, but when I add my testing for example " this is a test \[support!\]"

When I view the content, it just show \[support!\], which is suppose to show "hello world" according to my filter.

I did put a drupal\_set\_message($op) on my hook filter, but it seems to only show "list" not process or prepare or the rest of the $op.

What I'm doing wrong?

Welcome your advice

# Answer
> 2 votes
Given that you are only seeing 'list', I would make sure that your filter is added to an existing Input Format (check at `admin/settings/filters` and click on configure next to the appropriate input format) and also that all caches are cleared. Sometimes if you start entering/coding a filter and it runs before you've got all the kinks worked out, the `case 'no cache'` gets in the way and stores the initial/wrong result. Until you are sure of everything, you may want to change that to `return TRUE;` as well.

---
Tags: views, input-formats
---


title: Minutes of meeting module for drupal 7

text:
# Question
Title: Minutes of meeting module for drupal 7
I have a new requirement. I need a minutes of meeting module. I.e. after each meeting i.e. weekly they will add action items and assign it to some user and as soon as the user logs in, it should be shown to him. So is there any existing module which is even close to this. I don't mind sitting and customizing the module.

# Answer
> 2 votes
I'd use a custom *Action Items* content type and then Rules to handle the scheduling and assignments. Rules and fields (via content types) should be flexible enough to handle such a workflow and they have the further advantage of being well-supported and documented.

---
Tags: 7
---


# Question
Title: Separate and display only particular parent term from a taxonomy vocabulary
Is there a module or a way to separate and display only a particular parent term from a taxonomy name in Drupal 7 for the admin, while adding the content.

Consider the home page main menu with vocabulary *Name*.

The home page main menu has the following taxonomy terms.

```
Hello
----Red
----Green
----Blue
Test
----Orange
----Black
----Violet

```

Here in my case I have a content type called Article(for example);

While admin is creating an article, I need to display only the taxonomy term related to *Hello*. Right now it is displaying all the taxonomy terms related to *Hello* and *Test*. Is there a way to separate the parent terms from the same Vocabulary Name.

# Answer
I think this is, what you searching for: Taxonomy Term Reference Tree Widget.

Here is a quote about it (from the module's project page):

> ... provides an expandable tree widget for the Taxonomy Term Reference field in Drupal 7. This widget is intended to serve as a replacement for Drupal's core Taxonomy Term Reference widget, which is a flat list of radio buttons or checkboxes and not necessarily fit for medium to large taxonomy trees.
> 1 votes

---
Tags: taxonomy-terms, nodes
---


title: Is there is a module like, "dbcm"?

text:
# Question
Title: Is there is a module like, "dbcm"?
Is there is a module like dbcm in Drupal 7?

I want to know changes happen in database, so I can update my production sites with all configuration changes: new block, new views, new (CCK) fields.

I have tried the feature module to export my changes, but it doesn't export everything I need. There are also some configuration changes missed after exporting.

Is there a module that store in the database such configuration changes?

# Answer
> 4 votes
Configuration management is a major initiative in the upcoming Drupal 8. Here's Dries talking about it.

In D7, you'll need cTools and Features and Strongarm. And here's a comparison of staging/deployment tools.

# Answer
> 1 votes
I think you're looking for the Activity module .... I could be wrong.

# Answer
> 1 votes
Did you tried looking into features module http://drupal.org/project/features? I have used it in my D6 project which involved mutisites and multiple deployments on various servers. The module is worth to have a look! and will suit your requirements if you are in early stage of your project.

Hope it helps.

Cheers!

---
Tags: 7, features, importing-exporting, deployment
---


# Question
Title: Adding a taxonomy drop down to drupal search
I am trying to add a drop-down containing taxonomy terms to my site's basic search. I have created a taxonomy term *category* and used search auto-complete module for providing auto-complete search functionality. Can anyone suggest me how to add taxonomy drop-down besides the search button on the search block and relate the drop-down selection with search text.

# Answer
> 1 votes
I think you will need to use custom search module. For auto-complete feature i think it is better to go with custom development rather than depending on contributed modules which will come with lot of unwanted features.

To preface :

You will need to use `hook_form_alter()` for add you custom field. Then with the help of `hook_search` you can inject your custom search criteria using search query extract and search query insert.

---
Tags: 7, taxonomy-terms
---


# Question
Title: how to change a theme through themekey on the contact page in drupal 7
I made a site in drupal 7 and used themekey (i'm using "nid" for all the pages) to have on every page a different backgrounds, this works perfect. But on the contact page i'm not able to find the way to do this, what are the settings in themekey to set a different background in the contact page.

Thx Fred

# Answer
I think setting `drupal:path` to `contact` should do the trick.
> 1 votes

---
Tags: theming, emails
---


title: Nodes with comments in View

text:
# Question
Title: Nodes with comments in View
I want to create a view that returns all nodes of type X. Beneath each node I want to return the comments for that node as well.

* Node 1
    1. Comment 1
    2. Comment 2
    3. Comment 3
* Node 2
    1. Comment 1
* Node 3
    1. Comment 1
    2. Comment 2

Something like above. Is that possible?

# Answer
> 3 votes
Create a new View, Give it a Name

* Select "comments" for the show option
* Display Formats should be Unformatted of Fields -- Not Comments
* Hit Continue & Edit
* In d7 the content relationship is going to be added for you automatically (just be aware)
* Add a new field (Content: Title) -- You might want to exclude it from display
* Under the Format settings there's going to be a Grouping field option, select Content: Title.
* Save Your View.

That should do it. Sorry is so plain, the views UI is not the easiest to explain, if I tried this post will be insanely long. I try capturing the key details.

Hope this helps.

# Answer
> 0 votes
You may be able to create a comment view (select View Type:Comment when creating the view).

Then add a relationship using Comment:Node, and add the comment and node title fields to the view.

Then set a filter on Node:Type = 'X'.

# Answer
> 0 votes
You can also create a simple node view and then in the Format section choose show content and then when you get to select the display (Full content, Teaser etc) tick the 'show comments' box.

---
Tags: 7, views
---


# Question
Title: What is the difference between _form_validate vs form_validate?
I'm unsure which one you should use for a form\_validation.

Seeing that `_form_validate()` starts with a `_` makes it a private function following the Drupal coding standards if I'm not mistaken.

So my guess is that a form validation should be done with `hook_validate()`.

But the question remains: what's the difference between the two and where should they be used?

---

EDIT: I misunderstood the `hook_validate()` which is not the `_validate` "hook" used in the form API. I'll leave the question unchanged so other users can learn from my mistake.

# Answer
You're totally correct, Drupal's coding standards denote anything with a `_` prefix is seen as a pseudo-'private' function. As such the `_form_validate()` function was never meant to be called directly. Unless you really need to use it, and you're absolutely positive there's no other way to accomplish what you want, I wouldn't advise using it.

In fact only one function in the whole core system calls `_form_validate()`: `drupal_validate_form()`. It would stand to reason that you should be using *this* function instead (being that it's not marked as a private function).

These are the functions that Drupal uses internally to validate a managed form, so if you're using the Form API correctly you should never need to call them. Adding validate handlers to a form to validate individual elements is the correct way to do things.

Just to clear up a wee bit of terminology as well, `hook_validate()` has nothing to do with the form API as such; it's used by node-providing modules to validate nodes before saving. The validation handlers that you add to forms (with custom forms, or through `hook_form_alter()`, don't have a particular 'Drupal name' that I'm aware of.

Also, you don't actually even need to use the standard named `_validate` function if you don't want to...you can add a function with any name as a form validate handler:

```
$form['#validate'][] = 'my_strangely_named_function';

```

Drupal just looks for `FORMNAME_validate()` by default, and runs it if it exists.
> 7 votes

# Answer
hook\_validate performs node validation before a node is created or updated. This hook is invoked only on the module that defines the node's content type.

\_form\_validate checks if all required fields are filled and if max lengths of text field is not exceeded. If it finds any errors of such kind it fires form\_error or form\_set\_error functions.

You need to use hook\_validate when you define a new node's content type in your module and want to do some customized validation for this content type. This hook won't work for non-node forms.

Generally you won't need to call \_form\_validate, because it is being called automatically during form submission process.

The best practice to validate an arbitrary form is to create a custom validation function.

For example you have a function that defines your form:

```
function YOURFORM_form(){
    // form definition
}

```

The custom validation function for this form would be

```
function YOURFORM_validate(){
    // form validation
}

```
> 3 votes

# Answer
I suppose it's a custom form that you'd like to validate?

If your form function is called `mymodule_form()`, then you should add a function called `mymodule_form_validate($form, &form_state)`. That function will be called automatically, and you'll be able to validate the submitted values using `$form_state['values']`.

If there are errors, you should call `form_set_error()`, which will prevent the submission and notify the user.

`hook_validate()` is only used to validate node submissions, if your module provides a content type, and can't be used to validate any other forms.
> 2 votes

---
Tags: forms, nodes
---


title: User-selectable CSS style

text:
# Question
Title: User-selectable CSS style
I have three CSS versions (default CSS, black on white and white on black for visually impaired users) of my drupal-7 website to be selected by users if they need to.

And I just have no idea how to do this with drupal... I would like to add a drop-down list in the footer to change the CSS used. Then, I imagine I would have to store it in a session variable or a cookie and change the CSS according to this value.

# Answer
> 2 votes
There may be a more elegant way to do this, but I would use the Switchtheme module, which provides a block that allows users to switch themes.

To make this work, you will have to create three separate themes, one for each option. However, this is not as complicated as it sounds. Just make the black-on-white and white-on-black themes subthemes of your main theme (the one with default CSS); then all you will have to do is set up the subthemes one time and add the CSS.

---
Tags: theming
---


title: menu home item stay's on every page

text:
# Question
Title: menu home item stay's on every page
i made a site through artisteer and i wanted to have a different background on each page, i did this with themekey and it worked. My layout is a header, content and left sidebar with main menu. The problem is that when i'm on the home page the home menu item is correct and located in the sidebar...when i 'm on the other pages the home menu item is located above the contentblok instead of the left sidebar....what can i do to remove from every page the home item so it only appears in the menul ist in the left sidebar.. Thx in advance Greetz fred

# Answer
Have you tried going to the blocks administration page and checking which blocks/menus are being shown where? This will allow you to locate the one that you don't want displayed; if it's a menu, you can then go to the menu administration page, find the menu in question, and delete the home page link from it.

Make sure you visit the administration page for the theme that is causing the problem; block placement is configured separately for each theme.
> 0 votes

---
Tags: routes
---


title: Saving a views sql query

text:
# Question
Title: Saving a views sql query
I am using Drupal 6, and Views 2.0; I need to create a node where one of the fields is a filterable view. I then need to store the final SQL query of the view in the database.

How would I add the block view to a node creation page?

# Answer
> 0 votes
Unfortunately I wasn't able to solve this issue, so I did a little bit of a work around.

What I did was built a content type where the user could specify what data he/she needed by use of a form and fields.

I then took the user input and built a dynamic sql query to output the required data.

Its a pretty dirty way of doing it... but until I find another solution, I'll have to use it.

---
Tags: views, nodes, database
---


# Question
Title: Adding Roles with Rules upon Webform submission not working — Why?
Here's what I have done so far (in Drupal 7):

1. Created a webform quiz that only validates if all answers are correct
2. Created a role called "Mid-program quiz: Passed" that has permissions to view a particular page
3. Created a rule that says upon submission of the quiz, the submitting user should be granted the "Mid-program quiz: Passed" role.

But it's not working. The quiz is being submitted correctly but the role is not being assigned.

Here are the details of the rule that's failing to execute:

---

# Event

Event: After a webform submission has been added

# Conditions: Webform has name

Parameter: The form id of the submitted form: \[form\_id\], Webforms: Mid-program quiz

# Elements

(Here I wasn't sure whether to use \[user\], i.e. the user submitting the webform, or \[site:current-user\], i.e. the currently logged-in user. So I did both.)

## Add user role

Parameter: User: \[user\], Roles: Mid-program quiz: Passed

## Add user role

Parameter: User: \[site:current-user\], Roles: Mid-program quiz: Passed

---

Can someone see where the problem is in this rule?

Thanks!

# Answer
> 0 votes
Adding Roles with Rules upon Webform submission not working — Why?

Okay, it looks like I figured it out:

---

* Event: After a webform has been submitted
* Condition: Webform has name
    + Parameters:
        - The form id of the submitted form: \[form\_id\]
        - Webforms: Mid-program quiz
* Action: Add user role
    + Parameters:
        - User: \[user\]
        - Roles: Mid-program quiz: Passed

---

So the confusing things to watch out for are:

* "After a webform has been submitted" is the one to choose, over "After a webform submission has been added."
* Webform Has Name has first parameter as ID and second as the webform (as selected from a list of webforms). It makes it seem like you're saying nid has to be equal to a title, which doesn't seem like it would work, but that's apparently not what's happening.
* Add user role takes simply Parameter:user, rather than site:user or any other attribute of user

---
Tags: webforms, rules, users
---


# Question
Title: Tokens not being replaced in node bodies
I have a default install of Drupal 7 with the Tokens module. I'm using `[current-page:title]` in a node body, but the content isn't being replaced.

I've looked for settings and at the Token module page, and nothing. What am I missing?

# Answer
> 7 votes
As @kiamlaluno mentioned in the comment, neither the token API in core nor the token.module replaces tokens in node bodies.

For that, you need a module like Token Filter.

---
Tags: 7, tokens, 10
---


# Question
Title: How does Drupal select default domain for relative links?
In one of our Drupal sites (core 7.14) links in two blocks displayed on the front page recently started using one of the alternate domains defined in the Apache config for the site instead of the primary domain. Neither block was changed recently. There are other blocks on the front page, and throughout the site, that were not affected.

The links in the block were of the style href="node/123" (without a leading slash). After investigating any modules or settings that seemed related to blocks or links, we added a leading slash to the links (i.e. href="/node/123") just to see if that had any effect. It did. The links using a leading slash selected the primary domain while the ones without a leading slash choose one of the alternate domains.

Any links in the block without a leading slash used the same alternate domain, so Drupal wasn't randomly selecting domains for each link.

The site launched using 7.10 and this odd behavior didn't start until we upgraded to 7.14. This only appeared in one site (so far); our other Drupal sites don't do this.

So my question is, how does Drupal choose the domain to use when rendering links and did that change somehow in 7.14? Does Drupal read the Apache config file?

Thanks for taking the time to read and consider my question.

# Answer
> 2 votes
You can specify the domain in settings.php - it's the variable called $base\_url (around line 271). It is not always necessary, but I've found it can prevent some unexpected errors if the domain is set explicitly. I'm not sure how Drupal decides the domain if the $base\_url is not set. By default, the $base\_url is commented out. To set it, remove the # in front and change www.example.com to your primary domain.

Are the links in the block built using a Drupal menu? I think when you set the leading slash, you actually circumvented Drupal's menu handling which is probably why it worked. If you set the $base\_url, I think you could remove the leading slashes from the links.

---
Tags: 7, blocks, navigation
---


# Question
Title: Change the filter widget type in a views
When adding a reference field as a filter in a views the default widget of the filter is drop down.
Is there a way to change it to a auto complete widget?

# Answer
I think you might be looking for something like Views Autocomplete Filters. The D7 version is in development but it sounds like it might be worth a try.
> 0 votes

---
Tags: 7, views
---


title: Entity custom displays

text:
# Question
Title: Entity custom displays
Is there a way to create multiple displays for an existing entity?

The node has already Full content, Teaser, RSS, Search index, Search result display types. I was wondering if I can add more to these or to any other entity.

Thanks :)

# Answer
> 1 votes
You can use display suite module. this is your answer

# Answer
> 2 votes
I think this is the answer I was looking for:

```
function hook_entity_info_alter(&$entity_info) {
  $entity_info['entity_type']['view modes']['custom mode'] = array(
    'label' => t('Custom view mode'),
    'custom settings' => FALSE
  );
}

```

---
Tags: 7, entities
---


title: Controlling the active menu item

text:
# Question
Title: Controlling the active menu item
I'm having problems understanding the menu system. I have an hosting node that has 3 pages: https://beta.ulyssis.be/hosting/

**Menu Hook**

```
function packages_menu() {
  $item['hosting']= array(
    'title' => 'Start',
    'type' => MENU_NORMAL_ITEM,
    'description' => 'Dit maakt ons ULYSSIS!',
    'page callback' => '_hosting_page_main',
    'access callback' => TRUE,
    'menu_name' => 'main-menu',
  );

  $item['hosting/bekijk']= array(
    'title' => 'Features',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 1,
  );

  $item['hosting/kortingen']= array(
    'title' => 'Kortingen',
    'type' => MENU_LOCAL_TASK,
    'description' => 'Deze groepen krijgen kortingen',
    'page callback' => '_hosting_page_discount',
    'access callback' => TRUE,
    'menu_name' => 'main-menu',
    'weight' => 3,
  );

  $item['hosting/pakketten']= array(
    'title' => 'Vergelijk',
    'type' => MENU_LOCAL_TASK,
    'description' => 'Vergelijk onze pakketten met elkaar!',
    'page callback' => '_hosting_page_compare',
    'access callback' => TRUE,
    'menu_name' => 'main-menu',
    'weight' => 4,
  );

  $item['hosting/bestellen']= array(
    'title' => 'Bestel Nu!',
    'type' => MENU_LOCAL_TASK,
    'page callback' => '_hosting_page_order',
    'access callback' => TRUE,
    'menu_name' => 'main-menu',
    'weight' => 5,
  );

  return $item;
}

```

**Problem** When navigating trough these pages, you'll notice that the top hosting menu item doesn't stay as 'active' menu item.

I'm having the same problem with other things, like when reading documentation, that the documentation menu item isn't active to. So I guess I'm not using the menu system as it should or that I'm missing some kind of knowledge about this.

*Does anybody know what I'm doing wrong?*

# Answer
> 2 votes
The "Hosting" li item is only active if you're on the Hosting page. If you're on a child page of "Hosting" won't be the "active" item, it will be the "active-trail".

You can change your navigation CSS to make the link look properly by changing .active to .active-trail:

```
.navigation li a:hover, .navigation .active a {
    background: none repeat scroll 0 0 #FFFFFF;
    border-color: #E99719;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

```

to

```
.navigation li a:hover, .navigation .active-trail a {
    background: none repeat scroll 0 0 #FFFFFF;
    border-color: #E99719;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

```

What might have confused you is that the link itself has a class of active, but its li wrapper does not.

---
Tags: 7, routes
---


title: Remove "where" clause in views 3

text:
# Question
Title: Remove "where" clause in views 3
I want to remove "where" clause for city and postal\_code in the views query. I found an example online for D6. I tried to change it a bit but it's not working. The "where" clause is still there. Below is my code. It was originally for D6.

```
function distsearch_views_query_alter(&$view, &$query) {
  if ($view->name == 'search' && $view->current_display == 'page_3') {
    // Remove the exposed filter conditions from the WHERE clause (WHERE city = MyCityInput)
    // and remove the corresponding args that were passed via the exposed filters
    // This effectively turns the city and zip code exposed filters into just text fields
    // that get used in distprox_mini_exposed_filter_proximity();

    $city = $view->exposed_raw_input['city'];
    $zip = $view->exposed_raw_input['postal_code'];

    // Remove the city or zip arguments (from the exposed filters)
    foreach ($query->where[0]['args'] as $key => $arg) {
      if ($arg == $city || $arg == $zip) {
        unset($query->where[0]['args'][$key]);
      }
    }

    // Remove the corresponding WHERE clause additions
    foreach ($query->where[0]['clauses'] as $key => $clause) {
      if (strpos($clause, 'postal_code') !== FALSE || strpos($clause, 'city') !== FALSE) {
        unset($query->where[0]['clauses'][$key]);
      }
    }
  }
}

```

# Answer
> 3 votes
It was a lot easier than I thought. I dsm the query and did it like below. Not sure it's the perfect way to do it but it's working.

```
function distprox_mini_views_query_alter(&$view, &$query) {
//dsm($query);
  if ($view->name == 'search' && $view->current_display == 'page_3')
    unset($query->where[1]['conditions'][0]);
    unset($query->where[1]['conditions'][1]);
  }
}

```

---
Tags: 7, views, location
---


# Question
Title: How can I sort options in an exposed views filter alphabetically?
I am using an exposed Views Selective Filter which limits the options available quite nicely. However the display order of the Options is what is causing me the trouble. Here is an example of my Select list:

Accomodation \- Camp Sites \- Hotels \- Rural Hotels

Beauty
\- Hair and Nails \- Makeup \- Spa

In the results these display exactly as I want them which is grouped by the Parent term (Accomodation, Beauty etc...). The trouble is that when I use the Views Selective Filter to only show options with results the list of options shows like this:

* Camp Sites
* Hotels
* Rural Hotel
* Hair and Nails
* Makeup
* Spa

What I really want to do is to resort that list alphabetically before it is displayed to the User. I guess Hook Form Alter is the way to go but I can find anything anywhere on how to create the alpha sort option. I hope that all makes sense. Thanks

# Answer
j.Rowny's answer doesn't work because $form\_state is not passed by reference. You must actually modify the $form variable. This worked for me:

```
function yourcustommodule_form_views_exposed_form_alter(&$form, $form_state) {
    foreach($form_state['view']->filter as $filter) {
        if($fid = $filter->options['expose']['identifier']) asort($form[$fid]['#options']);
    }
}

```
> 3 votes

# Answer
I think something like this might work:

```
function yourcustommodule_form_views_exposed_form_alter(&$form, $form_state) {
   usort($form_state['view']->filter, "yourcustommodule_cmp");
}

function yourcustommodule_cmp($a, $b)
{
    return strcmp($a["whatever_property_you_are_sorting"], $b["whatever_property_you_are_sorting"]);
}

```

Basically you're using PHP's usort on the filter form's view filters. I have never tested this and have no idea if it actually works. Also, you'd need to find what property of the filter you'd actually want to sort as I don't know it off the top of my head. Alternatively, in non-critical UI situations, I don't consider it a terrible "no no" to just use jQuery. It'd take a few lines of jQuery to sort your options.

See usort documention for more info on using usort.
> 0 votes

---
Tags: views
---


title: how to write a post-save trigger

text:
# Question
Title: how to write a post-save trigger
The node\_api hook provides a bunch of triggers which allows you to customize what might happen on, for example, a presave. The node\_api presave opcode triggers an action to occur after clicking on the node 'save' button but BEFORE the information in the node form is inserted into the database. I would like to create a trigger which will be a post-save trigger, to trigger my custom code after clicking the save button but AFTER the node info has been saved into the database. Does anyone have any ideas of how I might create such a trigger?

(I have read the documentation about how to create a trigger, I just don't know to code the trigger I am describing above.)

# Answer
Just to break the process down a bit (based on your other questions:,); when you submit a node form:

1. `node_form_submit()` calls `node_save()`.
2. `node_save()` immediately calls `node_invoke_nodeapi($node, 'presave');` to inform other modules about the presave.
3. `node_save()` then sets up a few properties on the node object, and the node record is written to the `node` table in the database using `drupal_write_record()`.
4. At the very, very end of the function (*after* the data has been written to the `node` table), `node_invoke_nodeapi()` is called again with either `'insert'` or `'update'`, depending on the current operation being run.

If you look through those functions, and the summary above, you'll see that the node data is 100%, definitely committed to the database **before** the `'insert'` or `'update'` operations are run for `hook_nodeapi()`.

If that's not happening for your installation I would strongly recommend replacing core with a fresh version, as it sounds like something's gone horribly wrong!

Getting to the actual question; the only way you can add a post-save hook is to add another line in the core `node_save()` function to invoke it. But you would be adding it immediately after the call to `node_invoke_nodeapi($node, $op);` (where `$op` is `'insert'` or `'update'`) anyway, so I'm not sure that would help.
> 1 votes

---
Tags: 6, nodes, rules
---


# Question
Title: Advantages of utilizing Entity Field query over views?
I've been reading a little about entity field queries.

What are the advantages of using entity field queries (EFQ) over views?

What are the largest pain points/disadvantages of using EFQ ?

# Answer
> 5 votes
Advantages of EFQ:

1. It's in Core, so you don't actually depend on an extra contrib module. Sometimes Views isn't considered an option.
2. It's very easy to handle programmatically, while Views is kinda awkward to handle in code.
3. I have made no performance measurements, but based on the fact that EFQ's are simpler than Views, I believe it will often have better performance.

Advantages of Views:

1. You can do (almost) arbitrary joins and collect most any kind of data. EFQ finds entites and their fields, period. It's also fairly easy to expose new data to Views. There's even a module for that.
2. It has a UI, and is as such far more user-friendly than building everything in code.
3. Views can easily be cached. An EFQ needs custom logic for this.

# Answer
> 4 votes
Views cannot perform queries on databases other than relational db (eg Mongodb | NO-SQL). However with EFQ, you can now perform complex queries against No-SQL databases including joins. Hence greater scalability and relatively good performace as well.

However as of now you can also combine Views UI with EFQ with an updated module called efq\_views. This way you get a UI and backend power of EFQ.

---
Tags: 7, entities, database
---


# Question
Title: Multilingual- can non-English languages be used without a prefix if they are the main language of the site?
I am trying to set up a multilingual web site, in English and Spanish. The way I want to setup the web site is:

> www.example.com: main page of the site in Spanish
>
> www.example.com/en: main page in English

and

> www.example.com/productos/ejemplodeproducto: Spanish product page
>
> www.example.com/en/products/exampleproduct: English product page

Instead, for the Spanish pages, there is always a prefix as well:

> www.example.com/es/productos/ejemplodeproducto: Spanish product page

Is it possible to not have a language prefix in the URL for the main language? That's how our site worked with Wordpress. We are using Drupal 7.

# Answer
> 4 votes
Yes, just go to 'admin/config/regional/language', click the edit link of your main language (Spanish), delete the prefix and save your changes.

If you have issues (like links still having the old prefix in them) then clear the caches ('admin/config/development/performance').

---
Tags: i18n-l10n
---


# Question
Title: Panels vs. Entity View Attachments (EVA)
Just digging into view, panels, contextual filters, etc. do build and render related entities. In this context I got the EVA module and now asking myself if I need EVA when using Panels? In a panel (page) I can include a pane to insert the result of a view - at least that is what I understood so far. Isn't EVA about the same thing? If I don't use Panels I see the point of EVA but if I use Panels anyway do I need EVA?

Thx for help, Marc

# Answer
> 3 votes
Whether you need a module or not depends on your use case; you certainly don't want to install and enable a bunch of modules that you don't need, as this will slow down your site and can cause other problems.

In this context, if Panels does what you need alone, then you don't need any other modules (and Panels can do so many things that it generally is sufficient by itself).

If you're committed to Panels, there's probably no need to use EVA-- and certainly if you're asking whether there's a need, you should try doing everything in Panels first, as that will be easier to maintain long-term.

EVA would be better if you wanted something more lightweight and just want to make changes for a few things; Panels is more useful if you want to take full control over the layout. EVA can also be used in circumstances where Panels integration isn't finished (e.g., Revisioning module and Panels' node add/edit forms).

That said, these two modules really aren't all that similar. Usually the layout modules are considered to be Panels and Context. Entity View Attachments is really just an extension of the attachment feature provided by the Views module. In that way, you could think of it as competing with content panes, another type of display provided by Views specifically for Panels (for reference, this question relates to the differences between attachments and content panes).

---
Tags: 7, views
---


# Question
Title: Adding META tag to nodes with a specific topic
If a node has a term reference to a specific term (say termid 123) I want to add this META tag to prevent search engine spiders from indexing the page:

```
<meta name="robots" content="noindex">

```

Is hook\_page\_build() the right hook for this?

# Answer
I think you definitely could use `hook_page_build()` (it would work), but since that hook is really intended for use with page.tpl.php, and meta tags are outputted in html.tpl.php, I think it might not be the 'Drupal' way.

Another option might be to use `hook_html_head_alter()`, which allows you to alter the `<head>` tags before they're rendered:

```
function MYMODULE_html_head_alter(&$head_elements) {
  if ($node = menu_get_object()) {
    $tid = function_to_get_term_id();
    $related_tids = field_get_items('node', $node, 'field_FIELD_NAME');

    if (!empty($related_tids) && $related_tids[0]['tid'] == $tid) {
      $head_elements['MYMODULE_meta_robots'] = array(
        '#tag' => 'meta',
        '#type' => 'html_tag',
        '#attributes' => array(
          'name' => 'robots',
          'content' => 'noindex'
        )
      );
    }
  }
}

```

You might also want to look at adding `rel="nofollow"` attributes on the links to those node in teaser displays, it might help speed up the process a bit.
> 4 votes

---
Tags: 7, meta-tags
---


title: Testing Services from outside site

text:
# Question
Title: Testing Services from outside site
I have been a little frustrated with trying to get outside applications to consume services. The services browser is invaluable in testing the services themselves but fails in helping test the servers. For instance, if I do a views.get in the service, it returns an array (php) with node references. When I try the JSON server module, it does not return the node references. Are there any recommendations on how to test different service functions out through JSON? I though that a PHP file could be written to do this, but I wanted to see if anything out there exists alreay.

# Answer
> 2 votes
I found a module called Web Service Clients. It is still unstable, but it works.

> Parallel to the Services module, the Clients module provides the ability to implement pluggable clients to external web services, including external Drupal sites running the Services module, the main use case being ingesting content from other Drupal installs via the Services module XMLRPC server.

# Answer
> 0 votes
```
/Load xmlrpc library
require_once('XmlRPC.php');
//Define Facekard server host
$facekard_server = 'localhost';

//Define facekard api server path
$facekard_server_path = '/wsdl/test/services';

//Make connection to server
$connection = new XmlRPC($facekard_server,$facekard_server_path);
//die(print_r($connection));

//Call remote function system.connect to get session id
$system_connect = $connection->call('system.connect');
//die(print_r($system_connect));
//Fetch sessid from xml object
$session_id = $system_connect->sessid;
$pass = '123456';

```

---
Tags: services, testing
---


# Question
Title: How can I exclude admin(uid=1) for "Views Argument PHP Validator code" which limit a view to a User’s uid value?
I have a page view with a menu tab and URL looks like `my-site.com/user/%/my-view`

I use `return $argument == $GLOBALS['user']->uid;` for default argument. And then I would like to limit the argument to only the currently logged-in user’s uid but how can I exclude admin role (uid=1)?

After reading this article I tried this but didn't work.

```
global $user;
if($user->uid != 1){
return $argument == $GLOBALS['user']->uid;
}

```

What I need to achieve is: Admin role(uid=1) can see `my-site.com/user/%/my-view` for all users but the rest of the users can see only the view according to their uid.

# Answer
> 0 votes
That is a basic PHP problem, it does not concern Drupal so much. You want to admit access to the admin user always, so you will want to exclude that user's user id of any checks. However, your logic is wrong. The correct version would be

```
global $user;
return ($user->uid == 1 || $user->uid == $argument);

```

Which firstly returns true if the user is the admin user and secondly returns true if the user id matches the argument.

---
Tags: 6, views
---


# Question
Title: Is there a way to create a hotel roommate system for a conference?
I will host a conference but the hotel room rate is very expensive. I am thinking of possible to create a system in drupal that allow registers to find a roommate to share a hotel room.

I saw the Room module, but I don't think this is what I am looking for.

# Answer
> 1 votes
There is no off-the-shelf module to do this, but you could set something up with a custom *Room share request* content type and then Rules and Entity Reference to handle the scheduling and assignments. Combining Rules, fields (via content types), and entity references should be flexible enough to handle such a workflow but it will require a little work to set up and may be too much work in your case.

Unless this is a huge conference, you might just go with the built-in forum module and allow users to post to the forum if interested and sort things out themselves. It requires very little set up and that way if your users don't actually use/need the feature then you won't waste time developing it.

---
Tags: 7
---


# Question
Title: drupal 7 get title token without anchor tag
I am using a view with a "content:link" field to display a custom link for each content in my block.

I have job listing in block and want to add a link for each job "Apply". When users click on "Apply" it will redirect to a webform with title of the respective job.

So in my View under the **REWRITE RESULTS** setting I have selected **Rewrite the output of this field** and added my custom anchor tag like below:

```
 <a href='20?id=[title]'>Apply Now</a>

```

It works but it's putting title with anchor tag. So the output URL becomes

```
 <a href='20?id=<a href="mysite/node/23">Team leader</a>'>Apply Now</a>

```

Here I want the value of title token, without an anchor tag. Is it possible? Or any other way to do this job?

# Answer
> 2 votes
I solved this issue. As described below :

We can use fields as token only whose we selected a block field.

I have selected title as block field with link to content node. so it was taking title anchor as token. I have removed tick for "Link to node" option from title field settings.

Now it's working fine.

---
Tags: views, nodes, webforms, navigation, tokens
---


title: Tabs in Form Module in Drupal 7

text:
# Question
Title: Tabs in Form Module in Drupal 7
How to create Tabs in form Module using FORM API in Drupal 7 and enable and disable them

# Answer
> 1 votes
The Examples for Developers collection of sample modules includes a sample implementation of vertical tabs in forms.

---
Tags: blocks
---


title: SSL Certification for Forms

text:
# Question
Title: SSL Certification for Forms
On my home page there are four links: Home, Contact Us, Company News, and Login.

I want Login and Company News to use SSL Certification.

How can I achieve this?

# Answer
You can use Secure Pages Module to configure https pages, but before that you need to get a valid SSL Certificate and get it installed in your server.
> 6 votes

---
Tags: ssl
---


# Question
Title: How to display image instead of a value in Drupal 7?
I'm having a field 'List (text)' in my custom content type as 'Select list' with Number of values as 'Unlimited', what I'm searching is to display an image instead of a value, for an instance I'm having values like Condo, Single Family & Multi Families so for these 3 different values I'm having 3 different logos which I want to display so what should I do to get this thing done?

# Answer
I can suggest an idea I used in Views output — this may help you find a solution for your case. I needed to display an icon near an article depending on its material type. I added a hidden PHP field with the following code (image names are not directly the same as the type name, that was the brief :)):

```
<?php
switch ($row->type) {
case 'article':
  print 'articles'; break;
case 'gallery':
  print 'gallery'; break;
case 'music':
  print 'music';
}
?>

```

And then a “type” field, which had the following override:

```
<img src="/sites/all/themes/my_theme/images/[php].png" alt="[type]" title="[type]" width="22" height="22" />

```

\[php\] is where Views output inserts the output of the PHP field I showed earlier. This same approach can be used to add a class to the HTML tag, and define a CSS image background for each class.

I hope this helps to find a solution for your problem.
> 2 votes

---
Tags: theming, media
---


# Question
Title: How can I use the "Taxonomy display" view on the Panels taxonomy override page?
I'm trying to change the weight of Page Manager module to enable the taxonomy term template in Panels. This is the error I'm getting:

```
Page manager module is unable to enable taxonomy/term/%taxonomy_term because some other module already has overridden with views_page.

```

I tried to change the weight directly from phpmyadmin but the weight field in page\_manager\_handler table is empty. I also tried the util module but it is not adding the required 'module weight' column in the module listing. Also it clashes with Module Filter module causing drupal to go crazy with a lot of errors.

Any suggestions?

# Answer
In this case, you don't need to adjust the module weight-- you need to remove the override on the taxonomy term pages.

Are you already overriding the taxonomy term display in Views? If so, just disable that view and the error should go away.

EDIT: If you still want to use the taxonomy view in Panels, you should edit the view as follows (I do this on one of my sites):

* Open the edit screen for the *Taxonomy display* view.
* Click *page*.
* Where it says *clone page*, click the triangle and select *disable page*.
* Click *Add*.
* Choose *Content pane*.
* Add the content pane.
* Click *Argument input*.
* For the first argument, choose *From panel argument* and *First*.
* For the second argument, choose *From panel argument* and *First*. (identical to the settings for the first)
* Go to your panel and add this content pane instead of the page (it will appear under *View panes*).

Why do you have to do this? Because otherwise Views and Panels will fight each other over who controls the page. By using a content pane, you avoid assigning a URL path in Views, allowing Panels to override the path successfully.
> 3 votes

---
Tags: 7, taxonomy-terms
---


title: right drupal sql query

text:
# Question
Title: right drupal sql query
what is the right sql query for drupal 7 if the query like this

```
SELECT MAX(nopeserta)
FROM `1_jp_peserta`
WHERE jpke=$q1 AND lomba=$q2 AND kelamin=$q3

```

i have tried in drupal like this

```
$q4 = db_query("SELECT MAX(nopeserta) AS nopeserta FROM {1_jp_peserta}
WHERE jpke=:q1 AND lomba=:q2 AND kelamin=:q3",
array(':q1'=>'$q1',':q2'=>'$q2',':q3'=>'$q3'))->execute()->fetchAssoc();

```

but the result is

```
PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters
were bound in jpeserta_form_submit()

```

# Answer
> 5 votes
When you use `db_query()` the query is executed for you, I think the error you're getting is because you're re-running `execute()` on it. Also it looks like you're trying to interpolate variables into a string using single quotes, when you need to use double quotes (or none at all in your case).

Try this:

```
$q4 = db_query("
  SELECT MAX(nopeserta) AS nopeserta FROM {1_jp_peserta} WHERE jpke=:q1 AND lomba=:q2 AND kelamin=:q3", array(':q1'=>$q1,':q2'=>$q2,':q3'=>$q3))->fetchAssoc();

```

---
Tags: database
---


# Question
Title: What operation should I use to write node's information in an email when the node is saved?
I am using `hook_nodeapi()` to display the node's information in an email when the user clicks on the "Save" button. I tried writing code for the "presave" operation, but that didn't work the way I wanted. I tried using a query to pull out the node data, but the data wasn't in the database until after the "postsave" operation.

Which `$op` is the right one for me? I tried 'insert' as well, and that didn't work.

# Answer
> 2 votes
Thanks to a bit of a to-and-fro in your other questions (this one and this one) I think I know what the problem is.

Without going into great detail, the content module (CCK) also implements `hook_nodeapi()`, in order to commit the field data to the database. What's currently happening is that the hooks implemented by your module are being called *before* the hooks for the content module, which means at the time your implementation of `hook_nodeapi()` is run, CCK's implementation *has not* run; hence the data not being found in the database.

In my experience unless you explicitly set the weight of certain modules, they're ordered by name alphabetically, and as your module name begins with 'a' it does make sense that this would happen.

To get around it you just need to increase the 'weight' of your module in the system. Have a look at How to update a module's weight for more information but essentially you want to run a query like this against your database:

```
db_query("UPDATE {system} SET weight = 100 WHERE name = 'yourmodulename'");

```

After that clear Drupal's caches and you should see things starting to behave a bit differently.

---
Tags: 6, hooks, nodes
---