title: How to change HTML output of main menu

text:
# Question
Title: How to change HTML output of main menu
When I output the main menu this is the html that gets generated:

```
<ul id="main-menu" class="links inline clearfix">
    <li class="menu-218 first active"><a href="/drupal/" class="active">Home</a></li>
    <li class="menu-294"><a href="/drupal/node/2">Page</a></li>
    <li class="menu-293 last"><a href="/drupal/node/1">page</a></li>
</ul>

```

However I'd like to completely restructure the menu like this:

```
<nav id="main-nav" class="animate">
            <div class="grid__wrapper">
                <div class="grid t--np nrp">
                    <a class="button animate" href="#" title="Sign up">SIGN UP</a>
                    <a class="button animate" href="#" title="Login">LOGIN</a>
                    <a class="main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp" href="<?php echo $front_page; ?>">HOME</a>
                    <a class="main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp" href="#">LINK 1</a>
                    <a class="main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp" href="#">LINK 2</a>
                    <a class="main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp" href="#">LINK 3</a>
                    <a class="main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp" href="#">LINK 4</a>
                </div>
            </div>
        </nav>

```

How can I change the html output of the menu as well as the links inside?

Ideally I'd like to output any menus as a element and be able to pass classes and an id to each one, the same also goes for the links inside.

Also the first two links in the menu are login and signup buttons which only display at certain screen sizes and have completely different classes to the rest of the menu links. Is this also possible to do?

I have tried altering the theme\_menu\_tree and theme\_menu\_link functions but am having no luck as I am somewhat of a beginner in PHP and Drupal.

# Answer
> 0 votes
Although I'm sure the answers posted are both great solutions I couldn't manage to get to grips with either. My solution was to create a custom `links__system_main_menu` function for my theme like this:

```
function mytheme_links__system_main_menu($variables) {
$site_frontpage = variable_get('site_frontpage', 'node');
  $html = "<nav id='main-nav' class='animate'>\n";
  foreach ($variables['links'] as $link) {
      if($link['href'] == '<front>') {
        $html .= "<a class='main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp' href='" .$site_frontpage ."'>" .$link['title'] ."</a>";
      }
      else {
        $html .= "<a class='main-nav__button animate grid__item xl--1-5 l--1-5 sp s--tbp t--tbp' href='" .$link['href'] ."'>" .$link['title'] ."</a>";
      }
  }
  $html .= "</nav>\n";

  return $html;
}

```

The separate rule for the front page link was due to receiving `<front>` in the href of the a tag normally.

One thing I couldn't do however was pass classes through to the function. from here in my page template:

```
print theme('links__system_main_menu', array('links' => $main_menu, 'heading' => t('Main menu')));

```

# Answer
> 4 votes
Most likely that your theme renders them menu either in theme\_preprocess\_page() in its template.php and passing it page.tpl.php. That's how Garland does it:

https://api.drupal.org/api/drupal/themes%21garland%21template.php/function/garland\_preprocess\_page/7

https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme\_links/7

Given your question, you're most likely going to end up with a custom theme, which is normal for most sites. The best way to tackle this is to change the logic in preprocess\_page to set it up how you like.

That's more sustainable and specific than altering or overriding theme\_links() globally in module-space.

# Answer
> 2 votes
Instead of trying to alter the html of the main menu the theme prints out for you, it could be easier to disable the main menu from the theme settings and use the Menu block module for rendering the menu, and Menu attributes module to add some additional attributes such as ids, classes, styles etc. to menu items. Those extra links, sign up and login, you can create at menu configuration itself at admin/structure/menu/manage/main-menu/add.

This way ýou can have high quality html with all the necessary ids and classes you'll ever need for making the main menu look what you want. You can also assign the menu block to any region you want.

https://drupal.org/project/menu\_block

https://drupal.org/project/menu\_attributes

---
Tags: routes, navigation
---


# Question
Title: Where in the database is the password reset form's expiration date set?
I'd like to be able to change the text in the temporary login page but I don't know where the expiration date for the form can be found. Getting the username is simple enough and I left the login button as is. The date is the only thing left.

Alternatively, can I do this in the drupal admin without having to code anything? Something similar to the email alerts, including options for multiple languages?

# Answer
The text for the One time password form is located in `user_pass_reset` form function in core.

While the user's password reset notification mail may be configured from the admin menu (**Administer \>\> Configuration \>\> People \>\> Account Settings**) there's no similar Admin UI based configuration of the reset form itself.

Though there doesn't seem to be a module to customize the form itself (based on my search), there do appear to be modules that offer alternative password reset methods that you could look at namely Password Reset and Simple Password Reset.

If you could consider taking a coding way, this could be achieved by using a `hook_form_alter` or `hook_form_FORM_ID_alter`

As for the expiration date drupal uses a default of 86400 seconds (24 hours). It would be stored in the `variable` table in the database with the name `user_password_reset_timeout` (note that when present the value 86400 would be serialized like all values in that table). If you wish to change this value consider doing it using `variable_set` through code. The equivalent drush command would appear an easier option though. Do make sure to update the email content on expiry time to avoid any confusion.
> 2 votes

---
Tags: 7, users
---


# Question
Title: Commerce Create Cart/Order without product
```
function create_init_order() {
  global $user;

  $order = commerce_cart_order_load($user->uid);

  if(!$order) {

    $new_order = commerce_order_new($user->uid, 'pending');

    // just consider i have generateEmail() and randomName($len) functions

    $new_order->order_number = $order_number = randomName(10);
    $new_order->mail = generateEmail();
    $new_order->hostname = randomName(10);

    commerce_order_save($new_order);
    unset($new_order);

    $order = commerce_cart_order_load($user->uid);
    $order->data['suburbs'] = $_REQUEST['suburb'];
    $order->data['truck'] = $_REQUEST['truck_size'];
    commerce_order_save($order);

  }
}

```

Hi guys this is for anonymous user creation of order if not existing yet, anything I missed why is not working well.

Specifically this part:

```
    $order = commerce_cart_order_load($user->uid);
    $order->data['suburbs'] = $_REQUEST['suburb'];
    $order->data['truck'] = $_REQUEST['truck_size'];
    commerce_order_save($order);

```

As i need suburbs and truck data before adding the line item.

Thank you in advanced.

# Answer
You are unsetting `$new_order` and then calling `commerce_order_save($new_order);` when $new\_order is null. It should use $order there. i.e.

not:

```
commerce_order_save($new_order);
unset($new_order);

$order = commerce_cart_order_load($user->uid);
$order->data['suburbs'] = $_REQUEST['suburb'];
$order->data['truck'] = $_REQUEST['truck_size'];
commerce_order_save($new_order);

```

but instead:

```
commerce_order_save($new_order);
unset($new_order);

$order = commerce_cart_order_load($user->uid);
$order->data['suburbs'] = filter_xss($_REQUEST['suburb']);
$order->data['truck'] = filter_xss($_REQUEST['truck_size']);
commerce_order_save($order); // here

```

It also looks like there's no need to save and reload the order there when one save would suffice.

Edit: OP has changed the `$new_order` code typo.

No need to save and load the order, the order\_id is already in `$new_order->order_id` after saving in `commerce_order_save($new_order);`

Your problem is probably a `NULL` or empty `$_REQUEST` var. Alternatively, you could add the fields to the order entity itself via the Fields UI.
> 0 votes

---
Tags: commerce
---


# Question
Title: Working with operators when manually specifying options for a custom views exposed filter
I am trying to build a custom exposed filter for a field using the Countries module.

Instead of listing all 200+ countries in the world, I want to list only three options **Japan**, **Not Japan**, and **All** (the site obviously has a Japan focus).

The sample code in this question is:

```
class views_handler_filter_MYMODULE_country extends views_handler_filter_in_operator {

  /**
  * Get value options for the select list.
  */
  function get_value_options() {
    // Replace $this->value_options with an appropriately filtered list.
    $this->value_options = function_to_build_filtered_list();
  }

}

```

The countries module stores countries as two-character ISO codes. Japan is `JP`. So I tried doing this:

```
    // Replace $this->value_options with an appropriately filtered list.

    $options = array();

    $options = array('jp' => t('Japan'));
    $options = array('us' => t('USA'));

    $this->value_options = $options;
  }

```

However, this code results in an error. Additionally, I don't know how to specify the operator, and when I think about it, I'm not sure how to handle the operator conceptually, either.

The logic should be this: either **JP** or **NOT-JP**. However, as I understand it, Views does not provide per-item operators; the operator is applied to the whole handler. "Is one of..." "Is not one of..." etc.

So, to do **Japan** or **Not Japan**, should I list **JP** for Japan and then all other possible values for all other countries for **Not Japan**? (That wouldn't take too long, I'm just scared of missing one.) Or is there some better way?

I'd appreciate any insight into how Views operators work and what approach I should take to building such a list.

# Answer
This doesn't answer your question exactly but gives an alternative.

Views exposed filters have a grouping functionality that can be used to create predefined value/operator pairs, so you can configure it to give options like Japan & not Japan without actually giving the user the ability to select the operator.

Much nicer for the user.

See the attached screenshot as an example of a possible solution to your problem that requires no custom code (note I am guessing that JP is the correct value in this case).

There are a couple of things to be aware of:

1. There is a bug where if you use is empty or is not empty you still have to enter a value, even though it is never used. See https://drupal.org/node/1818176
2. You might get undesirable results if not all your content has country data. The reason is that if a field doesn't have data it is NULL and in views/sql you need 2 separate operators to match not a string vs not null. The grouping in views doesnt' let you select multiple operators so you cant have both "is not Japan" OR "is null". If your country data is a required field you have no problem here. - It's possible in this case you could alter the views query if "Not Japan" is selected and add in the "OR country IS NULL". You should be able to do that in hook\_views\_query\_alter() and it still should be simpler than your current approach.

Note: I opened an issue for Add new filter operator "Is not equal to OR is empty"
> 3 votes

# Answer
One more alternative is Views Filter Populate module also have the **grouping functionality**. See the Video Tutorial for better understanding. I think this module will handle your situation see the screenshot or you will get some idea with this or at least it will help the future visitors, since the question is about the operators.

Single exposed filter that combines search across multiple fields. In Views 3 and Drupal 6 or 7 it is as simple as installing the Views Filter Populate

>
> 1 votes

---
Tags: views
---


# Question
Title: Drupal views get fields after filters without html markup
I have a question about Drupal 7 and Views. Let's assume that I have views where I extract 2 articles ordered by post date. I want to extract only title and trimmed introduction (trim configured in field settings in view)

Now I would like to extract this data programmatically without HTML markup. So the result will be similar to this:

```
array(
    0 => array(
        'title' => 'Lorem ipsum',
        'introduction' => 'Lorem ipsum dolar solor...'
    ),
    1 => array(
        'title' => 'Lorem ipsum2',
        'introduction' => 'Lorem ipsum2 dolar solor...'
    )
)

```

Is it possible to extract such information from views? I tried to do something like this:

```
$view = views_get_view('view_name');
$view->set_display('display_id');
$view->execute();
$data = $view->result;

```

But `$data` contain two elements with full nodes (all additional fields that I don't want to grab from database)

In addition for instance introduction is grabbed fully (must be trimmed somewhere in PHP).

Is it possible to do something like this:

```
$view->applyFilters(); //Like trim etc
$data = $view->getResults(); //return title + trimmed introduction but without HTML markup

```

Do You have any tips how to solve this problem? Is it possible for instance to pass template that will be rendered (where I could display only raw result without any HTML tags) or something?

Any help would be appreciated:)

# Answer
After suggestion from AlfredArmstrong I checked plugin style docs. To get filtered data without rendering html template simply do:

```
 $data = $view->style_plugin->render_fields($view->result);

```

Under `$data` will be array of filtered fields from view.
> 1 votes

# Answer
In your fields settings, open "Style settings:

Customize HTMLs, setting them both to *-None-* .

If that's not enough, Look at the right column. Section *Other*. Click on *Theme information* and provide custom tpl.php file for your field.
> 0 votes

---
Tags: views
---


# Question
Title: Changing the layout of user profile edit page
I am working on a website based on Drupal Commons. It uses Commons Profile Module to add extra fields to add user information.

I want to accomplish two tasks:

1. Change the layout of User Profile edit page i.e. : `mysite/user/%user/edit`. Where do I make the changes. Should I create a new `*.tpl.php` file and if so, then where?
2. I want to fetch the User Information Fields added by the Commons Profile Module to the edit form.

Please provide a solution in which both these issues are taken care of.

# Answer
I had to do this in the past and I went the module route.

Using Display Suite, Renderable Elements and Field Group I was able to fully change the layout of edit forms.

> Display Suite allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files. Screencast
>
> Renderable Elements enables you to register any forms and manage the display through an UI. It will also make (additional) elements available of existing entities on the manage forms/display screens or you can for example register the contact form and rearrange the fields through Field UI. Screencast
>
> Field Group will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

Edit: Also using Display Suite, you can add different views or blocks directly as fields to your node. So pulling fields from other entities shouldn't be a problem if you are good with views.
> 5 votes

---
Tags: users, 7
---


# Question
Title: How to change the link target in a entity reference display?
I'm on d7. I have two content types on my site, "link" and "Article". The link content type contains a link field from the link module that users enter a link to another site in to. I have the "link" content type referenced (thanks to the entity reference module) in my "article" content type and I would like for the link, when clicked, to open the referring page (offsite) in a new tab/window. How can I do this?? Any suggestions? Thanks.

# Answer
> 3 votes
You can configure a link field to open in a new window.

About halfway down the edit page for your link field, you'll see 'Link Target,' and that's where you set it.

# Answer
> 1 votes
Have you tried to add a simple jQuery script that adds `"target='_blank'` to the link field?

For example, if your link field ID is "field\_link\_und\_0" (search it in the HTML source), in the node-XYZ.tpl.php template file you can add the following code.

```
jQuery(document).ready({
    jQuery('#field_link_und_0').attr("target","_blank");
});

```

# Answer
> 0 votes
This is the real stuff:

just make this function in your template.php. It comes from file.module:

```
function **yourtheme**_file_link($variables) {

  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

  $url = file_create_url($file->uri);
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));

  // Set options as per anchor format described at
  // http://microformats.org/wiki/file-format-examples
  $options = array(
      'attributes' => array(
          'type' => $file->filemime . '; length=' . $file->filesize,
          'target' => '_blank',
      ),
  );

  // Use the description as the link text if available.
  if (empty($file->description)) {
    $link_text = $file->filename;
  }
  else {
    $link_text = $file->description;
    $options['attributes']['title'] = check_plain($file->filename);
  }

  return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}

```

# Answer
> 0 votes
I think there were two questions in one.

1. How to open the offsite URL in the referred node (Link) directly from the referring node (Article). For that, use the Link Replace Filter module.
2. How to open an offsite URL in a new browser tab — the easiest is to use for that is the External Link module.

---
Tags: 7, nodes, navigation, entities
---


title: Table of dynamic and static content?

text:
# Question
Title: Table of dynamic and static content?
With Drupal and views you can generate a table with for example a list of users and their contact details.

Let's say I have a user outside of the system that I want to add to the table statically, what's the best way to do this in Drupal?

The ways I am thinking of are:

- Write a module that db\_select or use enityfieldquery into an array, add the external user info and put it through theme table and outputs it on a page.
- Override the views template and add the user info there.

Are there better ways?

# Answer
Low level way is to use `hook_query_alter` \- with it, you can add `UNION` with anything.

More **direct Views way** is `hook_views_post_execute`:

> This hook is called right after the execute process. The query has been executed, but the `pre_render()` phase has not yet happened for handlers.
>
> Adding output to the view can be accomplished by placing text on `$view->attachment_before` and `$view->attachment_after`. Altering the content can be achieved by editing the items of `$view->result`.
> 2 votes

---
Tags: nodes
---


title: Chage View title with taxonomy term

text:
# Question
Title: Chage View title with taxonomy term
I have a Taxonomy Vocabulary as *People*. In it there are two terms *Board* and *Staff*. I've created a view with two displays, to display the people content with respect to taxonomy terms. The view title is Board Members.

I want to change the *staff* display title to be like Staff Members? How to change it?

I've filtered by using Contextual filters.

# Answer
Another method add this code in the template.php

```
    function template_preprocess_page(&$variables) {
      $current_path = drupal_get_path_alias();
       if($current_path == 'people/staff') {
       drupal_set_title('Staff Members');
      }
    }

```
> 0 votes

# Answer
1. In the contextual filters click on override title and set it to %1
2. Specify validation criteria to taxonomy term and select the vocabulary
3. Leave the views title empty.

This will set the present's term's title as the view's title.

If need you can add "text" %1 to display the text appended to the term's name.
> 3 votes

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


# Question
Title: Multivalue field displays duplicate values in views table
I have a content type with a multivalue entity reference field. In a view I show a list of nodes of this content type in a table. The column of the multivalue field (column C in the example) should show a comma seperated list of a field of the content type it references, these values are just single letters. In the view I enabled 'Display all values in the same row' for the multivalue field. Aggregation is on and the group column is set to Entity ID.

So for example, this should be the output of the view:

```
Column A     Column B      Column C
--------     --------      --------
value A1     value B1      X, Y, Z
value A2     value B2      Y, Z

```

When actually I get this:

```
Column A     Column B      Column C
--------     --------      --------
value A1     value B1      X, X, X
value A2     value B2      Y, Y

```

So what happens is, the first value in the list gets repeated as many times as the number of values.

I appreciate any help I can get!

This is the export of my view:

```
$view = new view();
$view->name = 'view_constitutionele_genetische_aandoeningen';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Constitutionele genetische aandoeningen';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Constitutionele genetische aandoeningen';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'field_gentest_accreditatie' => 'field_gentest_accreditatie',
  'title' => 'title',
  'field_gentest_gen_locus_chromos' => 'field_gentest_gen_locus_chromos',
  'field_mat_gentest_afkorting' => 'field_mat_gentest_afkorting',
  'field_gentest_materiaal' => 'field_gentest_materiaal',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'field_gentest_accreditatie' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_gentest_gen_locus_chromos' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_mat_gentest_afkorting' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_gentest_materiaal' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Entity Reference: Referenced Entity */
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['id'] = 'field_gentest_materiaal_target_id';
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['table'] = 'field_data_field_gentest_materiaal';
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['field'] = 'field_gentest_materiaal_target_id';
/* Field: Content: Accreditatie */
$handler->display->display_options['fields']['field_gentest_accreditatie']['id'] = 'field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['table'] = 'field_data_field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['field'] = 'field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['label'] = '';
$handler->display->display_options['fields']['field_gentest_accreditatie']['element_label_colon'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = 'Aandoening';
$handler->display->display_options['fields']['title']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['rel'] = 'width:600,height:400';
$handler->display->display_options['fields']['title']['alter']['link_class'] = 'mb';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Gen / Locus / Chromosoom */
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['id'] = 'field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['table'] = 'field_data_field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['field'] = 'field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['element_label_colon'] = FALSE;
/* Field: Content: Afkorting */
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['id'] = 'field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['table'] = 'field_data_field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['field'] = 'field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['relationship'] = 'field_gentest_materiaal_target_id';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['label'] = '';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['element_label_colon'] = FALSE;
/* Field: Content: Materiaal */
$handler->display->display_options['fields']['field_gentest_materiaal']['id'] = 'field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['table'] = 'field_data_field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['field'] = 'field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_gentest_materiaal']['alter']['text'] = '[field_mat_gentest_afkorting]';
$handler->display->display_options['fields']['field_gentest_materiaal']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_gentest_materiaal']['settings'] = array(
  'link' => 1,
);
$handler->display->display_options['fields']['field_gentest_materiaal']['group_column'] = 'entity_id';
$handler->display->display_options['fields']['field_gentest_materiaal']['delta_offset'] = '0';
/* Field: Content: Duur */
$handler->display->display_options['fields']['field_gentest_duur']['id'] = 'field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['table'] = 'field_data_field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['field'] = 'field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['element_label_colon'] = FALSE;
/* Sort criterion: Content revision: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'node_revision';
$handler->display->display_options['sorts']['title']['field'] = 'title';
/* 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']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'gentest' => 'gentest',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Content: Title */
$handler->display->display_options['filters']['title']['id'] = 'title';
$handler->display->display_options['filters']['title']['table'] = 'node';
$handler->display->display_options['filters']['title']['field'] = 'title';
$handler->display->display_options['filters']['title']['operator'] = 'contains';
$handler->display->display_options['filters']['title']['exposed'] = TRUE;
$handler->display->display_options['filters']['title']['expose']['operator_id'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['label'] = 'Zoeken';
$handler->display->display_options['filters']['title']['expose']['operator'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['identifier'] = 'title';
$handler->display->display_options['filters']['title']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
);
/* Filter criterion: Content: Language */
$handler->display->display_options['filters']['language']['id'] = 'language';
$handler->display->display_options['filters']['language']['table'] = 'node';
$handler->display->display_options['filters']['language']['field'] = 'language';
$handler->display->display_options['filters']['language']['value'] = array(
  'all' => 'all',
  '***CURRENT_LANGUAGE***' => '***CURRENT_LANGUAGE***',
  '***DEFAULT_LANGUAGE***' => '***DEFAULT_LANGUAGE***',
  'und' => 'und',
  'nl' => 'nl',
  'en' => 'en',
  'fr' => 'fr',
);
/* Filter criterion: Content: Type (field_gentest_type) */
$handler->display->display_options['filters']['field_gentest_type_tid']['id'] = 'field_gentest_type_tid';
$handler->display->display_options['filters']['field_gentest_type_tid']['table'] = 'field_data_field_gentest_type';
$handler->display->display_options['filters']['field_gentest_type_tid']['field'] = 'field_gentest_type_tid';
$handler->display->display_options['filters']['field_gentest_type_tid']['value'] = array(
  0 => '389',
);
$handler->display->display_options['filters']['field_gentest_type_tid']['vocabulary'] = 'taxonomy_categorie_gentest';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'view_block_const_gen_aan');
$handler->display->display_options['block_description'] = 'View Bloc: Const gen aan';

```

# Answer
> 2 votes
Views cannot remove certain duplications in multivalue fields, however, you can remove them using theme pre-rendering. This has been discussed at: https://drupal.org/node/1223448

Some variation of this might help you (in mytheme/template.php):

```
<?php
/*
* implements hook_view_pre_render()
*/
function mytheme_views_pre_render(&$view)
{
  switch($view->name)
  {
    case 'no_double_nodes_view':
      $nids = array(); // array of nodes to prevent duplicates
      $resultNoDoubleNodes = array(); // manipulated results
      foreach($view->result as $key => $result) // check each node of the result array on it's nid
      {
        $nid = $result->nid;
        if (!in_array($nid, $nids)) // if this node isn't a duplicate
        {
          $resultNoDoubleNodes[] = $view->result[$key]; // add it to the manipulated results
          $nids[$key] = $nid; // mark this nid as in results to prevent duplicates from now on
        };
      }
      $view->result = $resultNoDoubleNodes; // replace the old results with the results without duplicates
      break;
    default:
      break;
  }
}
?>

```

# Answer
> 0 votes
If your quest is just to hide the Duplicate Row from the table then jQuery is your friend in Drupal 7. I had same issue of duplicate rows, I hide it using:

```
// Hiding the duplicate rows from views table.
        var seen = {};
        jQuery('.view-name table tbody tr').each(function() {
            var txt = jQuery(this).text();
            if (seen[txt])
                jQuery(this).remove();
            else
                seen[txt] = true;
        });

```

---
Tags: 7, views
---


# Question
Title: Rules parameter description to appear in different lines
I want the description of a Rule to appear in two lines. In the description field I have tried '
' and '\n\r' but without any use.

```
  $items['my_custom_action'] = array(
    'label' => t('Some Label'),
    'triggers' => array('any'),
    'named parameter' => TRUE,
    'parameter' => array(
      'par1' => array(
        'type' => 'list<text>',
        'label' => t('Select an option'))),
        'options list' => array('1' => t('Option1'), '2' => t('Option2')),
        'description' => t('Line1') . '<br/>' . t('Line2'),
        'restriction' => 'input',
      ),
    ),
    'group' => t('My own group'),
  );

```

Please let me know how I can make the description appear in two lines.

It has to be simple. May be I am missing something basic :P

# Answer
> 0 votes
This should work

```
 $descp = "line1 </br> line2";

 $items['my_custom_action'] = array(
    'label' => t('Some Label'),
    'triggers' => array('any'),
    'named parameter' => TRUE,
    'parameter' => array(
      'par1' => array(
        'type' => 'list<text>',
        'label' => t('Select an option'))),
        'options list' => array('1' => t('Option1'), '2' => t('Option2')),
        'description' => t($descp),
        'restriction' => 'input',
      ),
    ),
    'group' => t('My own group'),
  );

```

---
Tags: rules, 7
---


# Question
Title: Alternative for Node Gallery in Drupal 7?
Will I be able to have show an image gallery for a multiple value image field on the node display in drupal 7 with some alternative module?

http://drupal.org/project/node\_gallery is only available for drupal 6

that´s anoying, every alternative that I´ve found is eighter abandoned or only for D6

# Answer
Field slideshow is a good alternative.
> 1 votes

# Answer
I stumbled upon your from two year question looking for an alternative for Node Gallery – and even though I don't know if your question is still valid, but at least I wanted to let you know a beta3 version of Node Gallery is available for dp7:

https://drupal.org/project/node\_gallery
> 1 votes

# Answer
Here are a couple other image gallery modules for Drupal 7.

Media Gallery

Gallery Formatter
> 0 votes

# Answer
Use the Gallery Formatter and Multiupload Imagefield Widget module to get your result.
> 0 votes

---
Tags: 7, media
---


# Question
Title: Generate Taxonomy Terms from Node Content Automatically
In Wordpress there was a plugin that could auto-create tags based on node content . I don't know how it did this but perhaps it looked up the most common words in the body content and used them as the tags. I have some posts that have lost their tags and it would be great to be able to auto generate some new ones from posts with a script rather than having to go back through and manually do them.

# Answer
> 3 votes
I haven't achieved such content based node tagging programatically on my own. But used a module named Open Calais which uses the Thomson Reuters web service to generate and classify taxonomy term from node body content. Though it was available with free key use the number of API calls were limited. This with More Like This might serve some purpose in case you are running on Drupal 6.

Another module that might be of interest is Autocategorise which appears to do the same by subjecting node content to regular expression rather than a web service API like calais. If you wish to code the logic yourself examining the module's code might give some ideas on implementation.

---
Tags: taxonomy-terms
---


title: How to style overall form

text:
# Question
Title: How to style overall form
**Problem**

I have a lot of pages with standalone forms. Because of webdesign issues I ended up using the form element to style.

The problem is certain actions cause the form-id to change.

```
<form id="user-profile-form">

 //a failed file upload causes the above to become

<form id="user-profile-form--2">

```

Which breaks a lot of my css.

An example form HTML profile:

```
<form id="user-profile-form" accept-charset="UTF-8" method="post" action="/drupalie/user/184/edit" enctype="multipart/form-data">
    <div>
        /*form is built in here*/
    </div>
</form>

```

Is there a way to add a CSS class to my form, add a class to the empty div which surrounds all the form elements or as a last resort, prevent the form increment on certain forms.

# Answer
> 2 votes
You can add classes you need directly to your form with `#attributes`. This is example directly from the official documentation:

```
$form['#attributes'] = array('class' => array('search-form'));

```

If it's not your code that creates form, you can add this with `hook_form_alter()`. Just be careful not to overwrite any attributes or classes that might be already in place:

```
$form['#attributes']['class'][] = 'search-form';

```

---
Tags: 7, forms, theming
---


# Question
Title: slideshow_view: how to rewrite the output?
I have a content-type "gallery " which is composed of:

* Field Image
* Field Link (which is an EXTERNAL link like www.google.com or http://exemple.org)

so i've created a view with the link field hidden(the widget of the link field is: "Title, as Link (default)") and the image field

how should I rewrite the output of the image field to put the external link into the image?

i've tried with this: `<a href="[view_node]">[field_image_1]</a>` but this is not working

# Answer
Method : 1

> 1. Place the link above the image field in the views.
> 2. Exclude it from display
> 3. Now rewrite the results of the image
> 4. a href="\[field\_link\]" image field
> 5. This will create the link to the image, so when clicking it will lead the page.

Method :2

> 1. Place the link above the image field in the views.
> 2. Exclude it from display
> 3. Select "output this field as link"
> 4. Click the replacement pattern here, and use the link in the text field
> 5. This will create the link to the image, so when clicking it will lead the page.
> 4 votes

---
Tags: 7, views, navigation
---


title: Content Type name not translated

text:
# Question
Title: Content Type name not translated
I created a custom Drupal 7 module that creates a custom content type. It looks like this:

```
$type = node_type_set_defaults(
array(
    'type' => 'featured',
    'name' => t('Featured'),
    'description' => t('The description of the featured item.'),
    'base' => 'node_content',
    'locked' => 0,
    'custom' => 1,
    'modified' => 1
)
);

node_type_save($type);

```

I have a nl.po translation file that contains the following entries:

```
msgid "Featured"
msgstr "In de kijker"

msgid "The description of the featured item."
msgstr "De beschrijving van het in de kijker item."

```

The description gets translated as I expect when switching between languages. The content type name does not get translated at all, only English is shown.

Any ways to fix this?

Thanks in advance.

# Answer
> -1 votes
I hope this like help you

How to Translate Content type name using i18n module?

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


# Question
Title: Google Maps Module custom markers and routeplanner
On my Drupal site, I have a nice Google maps module with custom markers.

The only thing I want to add is a route planner that makes use of my custom Markers.

Any suggestions?

# Answer
> 1 votes
Have you already tried https://drupal.org/project/routeplanner ? It's a very simple and lightweight Module to create a route from any address to a fixed point of interest.

---
Tags: google-maps
---


# Question
Title: How do I add a span "wrapper" to all required form fields?
In the current Drupal configuration required fields simply display an asterisk wrapped in span of class "form-required":

```
return '<span' . drupal_attributes($attributes) . '>*</span>

```

This isn't really suitable and I have noticed quite a few users miss the asterisk (poor visibility, etc.). To combat this I would like to apply much better styling / hinting to all elements of a required field (label, value, background, etc.).

How do I add a span wrapper to al required fields on the form?

```
<span class="form-field-required">
  <label for="some-field">Label</label>
  <div id="some-field">
  ....
  </div>
</span>

```

I presume I need to use hook\_form\_alter() but not sure what I need to check or how to output the original field data correctly/safely.

# Answer
> 2 votes
I'd suggest you create an implementation of the theme hook form\_element, to add a new class at the top level rather than an extra div which is simply redundant. That way you don't have to recursively process every form on the site looking for required fields. Unfortunately the standard form\_element implementation is not designed in a very helpful way, so you have to duplicate a lot of code:

```
  function mymoduleortheme_form_element($variables) {
    $element = &$variables['element'];
    // This is also used in the installer, pre-database setup.
    $t = get_t();

    // This function is invoked as theme wrapper, but the rendered form element
    // may not necessarily have been processed by form_builder().
    $element += array(
      '#title_display' => 'before',
    );

    // Add element #id for #type 'item'.
    if (isset($element['#markup']) && !empty($element['#id'])) {
      $attributes['id'] = $element['#id'];
    }
    // Add element's #type and #name as class to aid with JS/CSS selectors.
    $attributes['class'] = array('form-item');
    // extra code here --->
    if(!empty($element['#required'])) {
      $attributes['class'][] = 'form-element-required';
    }
    // <---
    if (!empty($element['#type'])) {
      $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
    }
    if (!empty($element['#name'])) {
      $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
    }
    // Add a class for disabled elements to facilitate cross-browser styling.
    if (!empty($element['#attributes']['disabled'])) {
      $attributes['class'][] = 'form-disabled';
    }
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";

    // If #title is not set, we don't display any label or required marker.
    if (!isset($element['#title'])) {
      $element['#title_display'] = 'none';
    }
    $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
    $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';

    switch ($element['#title_display']) {
      case 'before':
      case 'invisible':
        $output .= ' ' . theme('form_element_label', $variables);
        $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
        break;

      case 'after':
        $output .= ' ' . $prefix . $element['#children'] . $suffix;
        $output .= ' ' . theme('form_element_label', $variables) . "\n";
        break;

      case 'none':
      case 'attribute':
        // Output no label and no required marker, only the children.
        $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
        break;
    }

    if (!empty($element['#description'])) {
      $output .= '<div class="description">' . $element['#description'] . "</div>\n";
    }

    $output .= "</div>\n";

    return $output;
  }

```

---
Tags: forms
---


# Question
Title: How can I restrict users to some parents node with node hierarchy?
I have the Node Hierarchy module on my Drupal installation, and I am using the following hierarchy:

* Main Navigation (menu)
+ Art & Sciences
    - Art
        - Sciences
    + Economy
    - News
        * World wide
            * Other

What I want is that:

* Stephanie can add/edit/delete content any content from "Art & Sciences" section
* Stephanie can NOT add/edit/delete any content from other sections
* John can add/edit/delete content any content from "Economy " section
* John can NOT add/edit/delete any content from other sections

I tried to install Workbench access; it creates me sections, but users can choose any node for parent, whatever the hierarchy.

Node Hierarchy obviously add nodes to the "Main navigation" menu as menu links. Despite of editors, everyone can add a node in every menu, but I want to restrict each user to their section. I can assign only the section I want to a node, but in the hierarchy it's not correct.

Is there any module (even if I have to use more than one) I can use to achieve what I want?

# Answer
> 1 votes
Have you evaluated Organic Groups for this use case? Maybe you can implement your sections as groups.

Users join groups/sections. Inside their group, they are allowed to add+edit (because nodes belong to this group they are in). But nodes outside of their group, they can only view.

The "main site" can display all group content to visitors.

OG basicaly categorizes your nodes into access categories.

# Answer
> 2 votes
I suggest you attach a taxonomy vocabulary to your content type and use the Taxonomy Access module.

So, create your vocabulary:

* Arts & Science
* Economy
* News

Create roles based on taxonomy:

* arts\_role
* economy\_role
* news\_role

Assign permissions to roles:

* Edit terms in Arts & Science to arts\_role
* Delete terms from Arts & Science to arts\_role
* Edit terms in Economy to economy\_role
* Delete terms from Economy to economy\_role
* Edit terms in News to news\_role
* Delete terms from News to news\_role

Assign your users to your roles:

* Stephanie gets arts\_role
* John gets economy\_role

---
Tags: 7, users, nodes
---


# Question
Title: Is there a way to make sure an autocomplete field as an actual match?
I have an entity reference field in a content type in D7 set with an autocomplete widget. This is a required field, however if you type in something that doesn't have a match, it will still submit and save anyway.

Is there a way to make sure an actual match is found before allowing it to save?

# Answer
Per the comments above, this is a bug with Entity Reference Fields and is being engaged per the Issue Queue at:

https://drupal.org/project/issues/entityreference?text=autocomplete&status=All

Patches for the Simple batch seem to work from this thread: https://drupal.org/node/1974202

Patches for the Views reference seem to work from this thread: https://drupal.org/node/1702172
> 2 votes

---
Tags: entities, ajax
---


# Question
Title: How to filter a view according to nodes permissions
I would like my view to not display nodes to which the current user does not have access to.

I have implemented hook\_permission "access nodes of type mytype"

I have also implemented hook\_node\_access this way:

```
function mymodule_node_access( $node, $op, $account)
{

   if ($op == 'create')
    {
     $type = $node;
    }

   else
   {

    switch($node->type)
    {
      case "mytype":
        if ( !user_access("access nodes of type mytype") )
         {return NODE_ACCESS_DENY;}
        break;
    }

   }

 return NODE_ACCESS_IGNORE;
}

```

I set up the view to displays only nodes of type "mytype". When a user who does not have the permission "access nodes of type mytype" clicks on a link in the rows of the view, he gets the page "access denied" which is what I want. But I also want the view to not display the nodes of type "mytype" if a user does not have the permission to "access nodes of type mytype".

How do I implement that?

Thanks,

Baba

# Answer
The correct answer is actually here.

> It seems that a better way to control node access is through hook\_node\_access\_records and hook\_node\_grants as described here http://drupal.org/node/1260948. This works with views properly.
> 1 votes

# Answer
Take a look at Node access example, you can manage to make it work with Node access module.

> The modules provide roles and user specific security permissions for menus, menu items, nodes, and security integration into the administration and help systems.
> 0 votes

---
Tags: views, users
---


# Question
Title: All custom fields are missing in views 'add field' and 'add filter' forms (Drupal 7)
I'm experiencing some very bizarre behaviour on a live website.

I've just added a new date field to a bunch of content types. I now need to add this as a filter criterion to a view. The problem is that when I go to add the filter, it doesn't show any custom fields at all in the Add Filter list, and this is the same for Add Field. It happens in all views.

The really strange thing is that I've copied the live database down to my local dev machine to debug, ensured that I have the live tag checked out, and on my local machine it works absolutely fine.

I've tried clearing caches, logging in as a different user, disabling a new custom module (which shouldn't make any difference). I just don't get what could be causing this, because the code and db are exactly the same in the live and local environments.

Almost certainly I'm overlooked something small. Can anyone think what it could be? Has anyone seem this weirdness before?

Thanks

# Answer
To add to james-geldart's answer, I solved this same problem permanently (or for a few hours so far at least) by deleting every row of the table cache\_views in the site's database.
> 3 votes

---
Tags: views, entities
---


# Question
Title: Is there an input filter to add the class clearfix to all <p> tags?
I have a lot of inline images in my content. Most of the time I want to have some sentences and an image grouped together. To get a nice layout I have to mannually add `class="clearfix"` to all `<p>` tags. This is especially anoying because the class often gets lost when I edit the text in the wysiwyg editor.

Is there an input format, or some other easy way to do that automatically?

# Answer
> 3 votes
If you are trying to add the "clearfix" class to all of your paragraph tags, sitewide, it would probably be more simple to apply the "clearfix" properties to your "p" tag in your CSS files.

So you'd find:

```
.clearfix { ... }

```

and add in your paragraph tag like so:

```
.clearfix, p { ... }

```

Or copy the properties to your custom CSS file if you are worried about overwriting your changes.

---
Tags: input-formats
---


# Question
Title: How to show votes in view results by node id?
I installed the modules "rate (voting widget)" and "voting api". These modules work very well. I use views to get a list of nodes, and I added the voting results. Now I get a row for each vote, not for each node...

Views rows:

```
Node 1  --  angry: 1  happy: 1
Node 1  --  angry: 1  happy: 1

Node 2  --  angry: 1  happy: 0

Node 3  --  angry: 0  happy: 1

```

I want to group the results by node id, but this doesn't seem to work. what would be the easiest solution for this problem?

# Answer
> 1 votes
You can use hook\_query\_alter() in your custom module. Your code should look like this:

```
function MODULENAME_query_alter(&$query) {
  if(!empty($query->alterMetaData['view']->name) && $query->alterMetaData['view']->name == 'VIEWNAME'){
    $query->groupBy("node.nid");
  }
}

```

# Answer
> 0 votes
Easiest way is to use the built in aggregation functions in views / voting api. Select 'Relationships' under the 'Advanced' tab and add a relationship based on vote results:

```
Content: Vote results
Aggregate results of votes cast on Node.

```

The settings page lets you select whether you are aggregating for total votes, total score or even looking for an average.

---
Tags: 7, rating, views
---


# Question
Title: In the views are not displayed in the widget attributes field Form add to cart
I need to display the attributes of the widgets in the representations in the Form add to cart, at the moment I have shown only a choice of the number and Add to Cart button

Now this (is not right):

How do I need to make it (what you need):

In the second image I have in the base table of contents it is possible to select the field of Content: Product variations and in it there are all the necessary attributes to me colors and sizes.

In the first image I have a base table Search API prime field Commerce item: Form add to cart in does not display attributes such as color or size selection, I can not achieve that result as the second image I have of the field Content: Product variations, as it were, I did not connect the relationship, the entity does not have the right, there is a field Indexed, Commerce item and some of the fields Content.

This capability is necessary for me to make a quick order from the catalog.

# Answer
> 0 votes
Try to use instead *Content: Product variations* field *Content: Rendered Node* witn selected to render custom view mode like a "Product variation".

In display custom view mode should be disable all fields, but *Add to cart form* keep enable.

---
Tags: views, commerce
---


# Question
Title: Select only one radio button in a webform
What I need to do is allowing to select only one radio button in a multi-column radios, but each column is in a `<div>`, so they are like in different groups. Here is an example of the code:

```
$form['submitted']['fieldset_time']['time8am'] = array(
  '#type' => 'radios',
  '#options' => array('8:30', '8:45'),
  '#prefix' => '<div style="display:inline-block">',
  '#suffix' => '</div>',
  '#title' => '8 a.m.',
  '#weight' => 8,
);

$form['submitted']['fieldset_time']['time9am'] = array(
  '#type' => 'radios',
  '#options' => array('9:00','9:15','9:30', '9:45'),
  '#prefix' => '<div style="display:inline-block">',
  '#suffix' => '</div>',
  '#title' => '9 a.m.',
  '#weight' => 9,
);

```

With this code, the radios are displayed in 2 columns but I can choose two options, what can I do to only allow to choose one?

# Answer
> 0 votes
The problem with the radios approach is that they're separate form fields, so the browser is correctly allowing only one selection per field.

Instead, you should use radio - https://api.drupal.org/api/drupal/developer%21topics%21forms\_api\_reference.html/7#radio and specify the attribute of name to only allow one value to be selected.

I'm assuming this is going to be built programmatically in a loop instead of procedurally, but I'll demonstrate as if this was hard-coded. Also, in a perfect world you'd add markup in the theme, not in the form definition.

```
$form['submitted']['800_title'] = array(
  '#markup' => '8 a.m.',
  '#prefix' => '<div style="display:inline-block">',
);

$form['submitted']['830'] = array(
  '#type' => 'radio',
  '#value' => 'default',
  '#return_value' => '0830',
  '#title' => t('8:30am'),
  '#attributes' => array('name' => array('time')),
  '#prefix' => '',
  '#suffix' => '',
);

$form['submitted']['845'] = array(
  '#type' => 'radio',
  '#value' => 'default',
  '#return_value' => '0845',
  '#title' => t('8:45am'),
  '#attributes' => array('name' => array('time')),
  '#prefix' => '',
  '#suffix' => '</div>',
);

$form['submitted']['900_title'] = array(
  '#prefix' => '<div style="display:inline-block">',
  '#markup' => '9 a.m.',
);

$form['submitted']['900'] = array(
  '#type' => 'radio',
  '#value' => 'default',
  '#return_value' => '0900',
  '#title' => t('9:00am'),
  '#attributes' => array('name' => array('time')),
  '#prefix' => '',
  '#suffix' => '',
);

$form['submitted']['915'] = array(
  '#type' => 'radio',
  '#value' => 'default',
  '#return_value' => '0915',
  '#title' => t('9:15am'),
  '#attributes' => array('name' => array('time')),
  '#prefix' => '',
  '#suffix' => '</div>',
);

```

---
Tags: forms, webforms
---


# Question
Title: Detect when a user clicks file download link
I Have a view that outputs nodes, and also a link to download files that are attached to these nodes. I'd like to know when a user clicks one of these links, so that I can log the event.

All attached files are files in drupal's public file directory, inside a directory at sites/default/files

Is there good approach for detecting a click or file download in this case?

# Answer
Module Track da files (despite its goofy name) tracks both public and private files. Here is a quote about it (from the module's project page):

> ... enables the possibility to track how much visitors are viewing files on site.
>
> Every link to a file can be configured to be tracked. Then, a record is registered each time a visitor access the file from this specific link.
> 2 votes

---
Tags: files
---


# Question
Title: Admin menu for client, each menu for each content type
I want to create a admin interface for my client. For now, if my client wants to add an article, he needs to click *Content*, *Add content*, and select *Article* as content type; at the end, he can create a new node. This is not user-friendly.

I want to have *Article*, *Photo*, and *Video* as menu link in the Admin menu. If the user clicks on *Article*, it will show the list of all the articles list; I don't need to use the "type filter" to filter the content type, as users will click on the *Add* link in this list view directly, to add a node of each content type.

How can I achieve this?

# Answer
> 2 votes
Since you just need a few links, I would use the Shortcut module which is a Drupal 7 core module. The documentation on this is pretty good: https://drupal.org/documentation/modules/shortcut.

You can configure under user permissions whether the user can edit the menu themselves or not. You can have different shortcut menus for different users.

Out of the box, you can only have 7 shortcuts on the shortcut bar at one time. There appears to be a patch for this, but I haven't tried it yet myself: https://drupal.org/node/682000#comment-6493066

However, to display the shortcut toolbar, it appears you have to expose the Admin toolbar to that user. You can make the admin toolbar pretty minimal by just giving the tool bar and create content permissions to the user.

If you really don't want to expose the admin toolbar to this user at all, then you might want to go with a menu block that only this user sees (set under block config\>Roles). Your user would need to be given a unique role for this (which other users are not given). This assumes you have the Menu, Block and Menu Block modules installed.

# Answer
> 1 votes
Try to use Administration Views module This module override standard content list to configurable views. In next step, you can make individual view for even content type

You can make menu list, whether provided all required functional.

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


title: Drupal + MongoDB + ApacheSolr

text:
# Question
Title: Drupal + MongoDB + ApacheSolr
I'm developing a website which uses MongoDB drupal module, I also need ApacheSolr as search engine, I googled about the Compatibility of ApacheSolr and MondoDB but found nothing. Can I use Mongo as database and ApacheSolr as search engine (with search api) together?

# Answer
Given that Search API/Search API Solr use Drupal core functions for retrieving entity data in order to be database agnostic, and the MongoDB module just adds another database backend for storing items like fields, there wouldn't be a conflict. As long as you stick with Drupal core functions in your custom integration, you should be fine.
> 0 votes

---
Tags: search, database
---


# Question
Title: Create link to views page that preselects the filters of an entire vocabulary?
I have a view that filters by different taxonomy terms, using multiple vocabularies. Im using the better exposed filter module.

I need different links to this view page which make different options pre-selected. By copying the url from when 1 term is selected I can easily make a link which works in this way:

my-site/resources?tid%5B%5D=22&keys=

I also need to make a link where all the terms from a vocabulary are selected. The client for this website will be able to add new terms to this vocabulary. If I simply copy the url with all the terms selected then this wont select a new term when its created.

How can I create a link to the view page which preselects all the terms from a vocbulary, that will still select all the terms when new ones are created?

# Answer
> 0 votes
Based on the URL provided:

```
function MODULE_NAME_build_taxonomy_views_link($taxonomy_tid) {
  $vocabulary = taxonomy_vocabulary_load($taxonomy_tid);
  if (!$vocabulary) {
    return;
  }
  $term_ids = array();
  foreach (taxonomy_get_tree($taxonomy_tid) as $term) {
    $term_ids['tid'][] = $term->tid;
  }

  return l($vocabulary->name, 'resources', array('query' => $term_ids));
}

```

---
Tags: views
---


# Question
Title: Retrieve the list of users who have not taken the quiz
```
  $all_users =db_select('users', 'u')
  ->fields('u', array('uid'))
  ->execute()
  ->fetchAll();

  $quiz_nid = db_select('quiz_node_properties ', 'qnp')->distinct()
    ->fields('qnp',array('nid'))
    ->execute()
    ->fetchAll();

    foreach ($quiz_nid as $key => $value) {
      $quiz_id = $quiz_nid[$key]->nid;
      $quiz_takers = db_select('quiz_node_results', 'qnr')->distinct()
        ->fields('qnr',array('uid'))
        ->condition('nid',$quiz_id,'=')
        ->execute()
        ->fetchAll();
    }

```

$all\_users is the list of all users. $quiz\_takers is the list of users who have taken the quiz. Both $all\_users and $quiz\_takers are array of objects. I want list of users who have not taken the quiz. **($all\_users - $quiz\_takers)**. How to achieve this using **not in**(database query) or anything. Help needed.

# Answer
This is quite straightforward by using a custom function. I think udiff might work too, but I'm going without that.

But before that make one modification

```
$quiz_takers_uid = db_select('quiz_node_results', 'qnr')->distinct()
        ->fields('qnr',array('uid'))id
        ->condition('nid',$quiz_id,'=')
        ->execute()
        ->fetchCol();

```

This gives you an array of uids in quiz\_takers\_uid.

```
function getdiff($all_users,$quiz_takers_uid) {
  $remaining_users = array();
  foreach ($allusers as $user) {
    if (array_search($user->uid,$quiz_takers_uid) !== FALSE)
      continue;
    else
      $remaining_users[] = $user->uid;
  }
  return $remaining_users;
}

```

I just thought of something else, which would make it even shorter In fact, an alternative solution would be to also make

```
$all_users_uid =db_select('users', 'u')
  ->fields('u', array('uid'))
  ->execute()
  ->fetchCol();

```

then you could just do `$remaining_users = array_diff($all_users_uid, $quiz_takers_uid);`

as both are now arrays of uid.
> 2 votes

# Answer
If you have two array (one containing all the student, and another containing nids of students who took the quiz) than you try array\_diff(): Computes the difference of arrays

> $result = array\_diff($array1, $array2);

Example:

```
<?php
  $array1 = array("a" => "green", "red", "blue", "red");
  $array2 = array("b" => "green", "yellow", "red");
  $result = array_diff($array1, $array2);

  print_r($result);
?>

```

The result will be `Array ([1] => blue)`, you can see here the difference will of array1 from array2 so the result contains the elements of array1 not present in array2.

And this would be helpful as it won't require the additional database call.

---

However if you want to do it with the `db_select` query than check How do I use “NOT IN” in a query:

```
$query = db_select('node', 'n')->fields('n');
$query->condition('n.nid', array(1, 2, 3), 'NOT IN');
$nodes = $query->execute();

```

> $query-\>condition('n.nid', $array2, 'NOT IN');
> 0 votes

---
Tags: users, quiz
---


# Question
Title: Where does Drupal save the trim length for the body field?
When I navigate to *Manage display* for any node type that has a standard body field and click on the *Teaser* tab the default format will be "Summary or trimmed". The default trim length is 600 (characters), but you can change it to whatever you want and *Save* the new value.

However, I want to know *where* (i.e. in which table or variable) this value is saved.

(I need this information in order to find out what trim length to use when *comments* are emailed to users that subscribe to comment notifications. The project specification requests comment notifications to be trimmed to *same* length as the content type they're attached to.)

# Answer
> 7 votes
In Drupal 7, field settings are saved into `{field_config_instance}` and `{field_config}` database table.

Trim length for a body field is saved in the `data` column in the `{field_config_instance}` table. The `data` column is stored in BLOB format, so you are not able to see the value of this.

You can use the `field_info_instance()` function to extract information about a particular field in a particular entity bundle/type:

```
$body = field_info_instance('node', 'body', 'page');
print_r($body);

```

---
Tags: nodes
---


# Question
Title: How to auto purge old unapproved comments?
I would like to know if there is any way to automatically purge old unapproved comments on cron run.

The requirement is -- I have turned on email notification on new comments. I would like to approve only the genuine comments and leave the rest for auto-delete on passing certain time.

Of course I already have mollom, captcha and http:BL to fight spam.

# Answer
I'm not sure if there is a module which does that. However, you could do that with the help of some custom coding inside `hook_cron`:

```
function MODULE_cron() {
  // Find out the comment ids of the comments that are unpublished
  // and are older than 30 days.
  $comments = db_query('SELECT cid FROM {comment} WHERE status = :status AND created < :created', array(':status' => 1, ':created' => strtotime('today - 30days')))->fetchAll();
  $cids = array();
  foreach($comments as $comment) {
    $cids[] = $comment->cid;
  }
  comment_delete_multiple($cids);
}

```

You can change the time to fit your requirements. This will ensure that on cron run the comments which are older than 30 days and are still unpublished get deleted.
> 4 votes

---
Tags: 7, comments, advertising, workbench
---


title: register users automatically

text:
# Question
Title: register users automatically
I add a new text field that called real name(for entering the real first and last name). And a "selection filed" that user can select his field between A to D.

Now for registration we have 5 field.

1. Email
2. Username
3. Password
4. Real name
5. "Selection field"

And I have an Excel file that contains about 500 users data(all data are in there such as user name and password and ...)

Now I need a similar code to register them automatically in my drupal site.

How?

Note:In the "selection field" the choice are such as First-one First-two and so on.

Example:this is a similar column in my excel file

```
Username     password     realname     Email     SelectionFild
12321        12321        Mr.Bin       -         F1

```

Note:in this example - in the Email means the user haven't Email address. And F1 in the selection field means First-one.

# Answer
You can use feeds module which import data, uses, taxonomy term into Drupal website using CSV file.

In module page:

> Import or aggregate data as nodes, users, taxonomy terms or simple database records.
>
> * One-off imports and periodic aggregation of content
> * Import or aggregate RSS/Atom feeds
> * Import or aggregate CSV files
> * Import or aggregate OPML files
> * Create nodes, users, taxonomy terms or simple database records from import
> * Extensible to import any other kind of content
> * Granular mapping of input elements to Drupal content elements
> * Exportable configurations Batched import for large files
> 1 votes

---
Tags: users
---


title: How to use $contexts in Page Manager

text:
# Question
Title: How to use $contexts in Page Manager
Im trying to make a selection rule for variants in Page manger and it includes some data comparison so it has to be in php. My field data is inside the context, so the `$contexts` variable can be used, but I cant get the proper way to use it. In my case it is a field value of the node, that is specified by the argument in URL "node/%nid".

Can some body please give an example code to extract the field value from context in php?

# Answer
> 2 votes
First of all, I want to point out that since this issue got closed in December, ctools got much better support for handling fields in access rules.

With that said, `$contexts`, have a data value, which is either an object, or an array of objects, depending on whether your plugin requires one or more contexts.

To make the code easier to read, I usually do something like this: `$node = $context->data;`

Brief example code:

```
function contact_info_pane_content_type_render($subtype, $conf, $args, $context = NULL) {
  $block = new stdClass;
  $block->content = '';
  $node = $context->data;
  $block->content .= count($node->field_email) > 0) ? $node->field_event_mail['und'][0]['email'] : '';
  $block->content .= count($node->field_phonenumber) > 0) ? $node->field_event_phonenumber['und'][0]['safe_value'] : '';

  return $block;
}

```

# Answer
> -1 votes
panels php https://drupal.org/sandbox/rogical/2121111

This module would solve this issue

---
Tags: 7, chaos-tool-suite
---


# Question
Title: use content type field value as css class in views
I have a content type article with a field called 'type'. Based on the value of this field I want to display my content type differently in a view that I created with the Views module. In order to do that I would like to add the value of the type field as a css class to each item in that view.

# Answer
The easiest way to achieve this was actually use the views module itself. The value of the type field can be easily used as a row class. Thanks for the other suggestions, but in the end this was all I needed.
> 1 votes

# Answer
You have several solutions, you can create a contextual filter based on `type` and embed your view with this code `views_embed_view('yourview','page',$field['type'])` in this way a special view based on this filter will be loaded.

the second solution is to create separate pages for different types, for example page\_type1, page\_type2 and ... , then in this code `views_embed_view` use the relevant `page` based on the `type`.

I've used both methods and it works
> 0 votes

# Answer
Using the code below you can add class to the fields as per the value of field\_type

```
$form['field_type']['#attributes']['class'] = array(
 drupal_html_class($form['field_type']['und'][0]['value']),
);

```
> 0 votes

# Answer
I believe the Semantic Views module supports tokenized classes. Here is the module description:

> This Views plugin makes unformatted styles, field row styles and other output more readily configurable without needing to override template files. Instead of overriding row style templates for views where you want to specify different HTML elements (tags) and class attributes, you can specify these inside the Views UI and avoid overriding templates for each view.
> 0 votes

---
Tags: views
---


# Question
Title: Is there anyway 'odd' and 'even' classes can be attached to node teasers so that they can be striped with different colored backgrounds?
Is there anyway 'odd' and 'even' classes can be attached to node teasers so that they can be striped with different colored backgrounds?

In the same way that table rows can be striped.

# Answer
Looking at the node.tpl.php doc page, there seems to be a way that you can print this in a node template.

Put the following in the node.tpl.php file (if your theme has no node.tpl.php file, just copy from modules/node):

```
<?php print $zebra; ?>

```

You can use Views module to generate node lists in the exact same criteria that Drupal core front page has.

1. Install Views module
2. There is a Views template called "front page" that you can edit.
3. Just save the View and make sure you have set the front page to this new views based page.

By default, Views adds odd/even classes to the node list. You can toggle this feature in field settings. Choose "Row style" to "nodes" and under settings, toggle this feature.
> 3 votes

---
Tags: nodes
---


title: Load nodes with a fields condition

text:
# Question
Title: Load nodes with a fields condition
I have node type called online\_users. The node type has a field called field\_website\_id. I would like to get the nodes that has a specific field\_website\_id.

I have try to make the following action but gets an error:

```
function get_list_of_users($site_id) {
$query = new EntityFieldQuery();
  $entities = $query->entityCondition('entity_type', 'node')
  ->propertyCondition('type', 'users_online')
  ->propertyCondition('field_website_id', $site_id)
  ->execute();
  if (!empty($entities['node'])) {
    $node = node_load(array_shift(array_keys($entities['node'])));
  }
}

```

The error:

> PDOException: SQLSTATE\[42S22\]: Column not found: 1054 Unknown column 'node.field\_website\_id' in 'where clause': SELECT node.nid AS entity\_id, node.vid AS revision\_id, node.type AS bundle, :entity\_type AS entity\_type FROM {node} node WHERE (node.type = :db\_condition\_placeholder\_0) AND (node.field\_website\_id IS NULL ) ; Array ( \[:db\_condition\_placeholder\_0\] =\> users\_online \[:entity\_type\] =\> node ) in EntityFieldQuery-\>execute() (line 1140 of /Applications/MAMP/htdocs/Drupal/includes/entity.inc).

What is the right way to do this?

# Answer
> 2 votes
To filter by fields you should use `fieldCondition()` method instead of `propertyCondition()`

```
function get_list_of_users($site_id) {
  $query = new EntityFieldQuery();
  $entities = $query->entityCondition('entity_type', 'node')
    ->propertyCondition('type', 'users_online')
    ->fieldCondition('field_website_id', $site_id)
    ->execute();
  if (!empty($entities['node'])) {
    $node = node_load(array_shift(array_keys($entities['node'])));
  }
}

```

---
Tags: nodes
---


# Question
Title: How to get rid of empty blocks on the dashboard?
I created a View called *Recent comments* and added a block to my dashboard. Afterwards, I deleted the View, which results in an empty block on my dashboard

and the following error message:

> Notice: Undefined index: recent-comments-block in dashboard\_page\_build() (line 192 of
> C:\wamp\www\mysite\modules\dashboard\dashboard.module).

I tried to drag the empty block away after clicking *Customize dashboard*, but every time I hit *Done*, it is displayed again. Clearing caches did not help either.

What should I do to get rid of the empty block?

# Answer
I think this is a long-standing issue with dashboard blocks. See the discussion, and several patches, here: https://drupal.org/node/936798

I haven't tried any of these patches myself.

If you just want to get rid of the error, I believe you can delete inactive blocks in the database directly, as described here: https://drupal.org/node/1202500

The gist is that you look for and remove blocks in the block table where region = dashboard\_inactive
> 1 votes

# Answer
**Fast Solution:**

1. Create a new block view with the same machine name (recent-comments)
2. Disable the block from dashboard configuration page `admin/dashboard/configure` \- make sure to set the region to none.
3. Delete the created block view in step 1

**Another solution:**

Delete the deleted block (recent-comments-block) from database directly

```
DELETE FROM `block` WHERE `delta` like 'recent-comments-block';

```
> 1 votes

---
Tags: 7, views, blocks, dashboard
---


# Question
Title: Multiple choices select with data module created view
on my website I have a custom table, and I used the data module to create a view that uses the entries in that table. I have created an exposed filter for one of the columns. Since I needed a select form and only search box was available, I used this code:

```
function mymodule_form_views_exposed_form_alter(&$form, $form_state) {

$form['myfield']['#type'] = 'select';
$form['myfield']['#multiple'] = true;
$form['myfield']['#default_value'] = array("" => "All");
$form['myfield']['#options'] = $values;
$form['myfield']['#attributes'] = array('size' => 10);

```

}

The problem is that when I select multiple values, it performs an "AND", but I need an "OR". How can I procede? Thanks!

# Answer
\*markus\_petrux\* answered, and *josepvalis* gave a helpful example of this in Drupal Groups in 2010.

You can use hook\_views\_pre\_view to alter the filter to use 'OR'. Trimming *josepvalis*'s example, try redefining the filter & applying that:

```
function my_module_views_pre_view(&$view) {
    $new_view_filters['field_multiselect_value'] = array(
        'id' => 'field_multiselect_value',
        'table' => 'my_table',
        'field' => 'my_column',
        'operator' => 'or',
        'value' => $array_of_values,
        'group' => '0',
        'exposed' => FALSE,
        'relationship' => 'none',
    );
    $view_overrides = array();
    $view_overrides['filters'] = $new_view_filters;
    foreach ($view_overrides as $option => $definition) {
        $view->display_handler->override_option($option, $definition);
    }
}

```
> 0 votes

---
Tags: forms
---


title: About Drupal 7's permissons

text:
# Question
Title: About Drupal 7's permissons
I'm new to drupal and when I looked at table `{role_permission}`, I found that permissions were stored as text string (e.g. "edit own page content"). But when I did a grep in drupal's folder, for some permissions they only appeared in \*.test files (In those files, some users with those permissions are created). It seems that some permissions, like "edit own page content", are not used at all, otherwise they should appear somewhere else when they are checked.

Any insights on access control mechanism in drupal would be appreciated.

Thanks, ZM

# Answer
> 2 votes
A straight grep for the full string may not find these, but they're used. For instance look in the `modules/node/node.module`, where you find calls such as:

```
if (user_access('edit any ' . $type . ' content', $account)
  || (user_access('edit own ' . $type . ' content', $account)
  && ($account->uid == $node->uid))) {

```

Note that the string is constructed on the fly, where the content type (e.g. *page*) is inserted into a template to form the string "`edit own page content`".

These strings are mostly used to call `user_access`, so to see where and how they're used, you may want to search for this function.

---
Tags: 7, users
---


# Question
Title: How to remove 'By term' and 'View' tab being displayed at top of pages?
On a Drupal 6 site, I have these annoying 'View' and 'By term' tabs being displayed on all node types. I am wondering how to remove/disable both of them?

# Answer
'By term' seems to be generated by one of the views in Organic groups: posts\_by\_term. You should be able to disable it at admin/build/views. Here's the issue https://drupal.org/node/1635082.

The View tab should not be displayed if it's the only tab, for example for authenticated users who don't have permission to edit the node.

Removing the View and Edit tabs, should you want that, is a bit complicated because you still might need them in some situations. Here's a pretty thorough conversation about that: https://stackoverflow.com/questions/3530756/how-to-hide-edit-view-tabs.
> 2 votes

---
Tags: 6, taxonomy-terms, routes
---


title: How can I translate content type names?

text:
# Question
Title: How can I translate content type names?
I am using Drupal 7 and have installed a translation module and enabled node and content translation, but I have a problem: In page `/admin/content` or `node/add` the content name is not translated. **I translate the content name string in the translation interface but they are not translated in related pages such add or manage content.**

Please tell me how can I translate content type names.

# Answer
Provided you're site is using a single (non-English) language, and you've installed the content type modules *before* you enabled the translation module, you have this problem because the strings with the content names are already imported into Drupal and any translation done after that point in the translation interface will not have any effect (unless you uninstall the content type, and then reinstall it again).

Instead of toggling installation (which may wipe out any content associated with the content type), navigate to *Administration » Structure » Content types* and click *Edit* for the content type you want to translate.

There you will see the human-readable name of the content type in a text field. Edit this field to the translated string you want, and click *Save content type*.

(The same goes for the other fields that appear in the content type UI, such as "Description" and field names.)

However, if your site is multi-language, I really think this is a bug in the Internationalization module, and as such is off-topic here. See Translate interface for nodes, fields, etc. show wrong language in the column for the issue.

However, I was able to get the node types translated at my site by doing the following:

First, I made sure that I installed the Internationalization module *before* I added any languages. I also made sure that I used English as the *default* language all the way during the translation process.

So you do the following with English as the *only* language enabled (if you've got additional languages enabled, uninstall them, you will also need to disable and uninstall the **Internationalization** module and all its helper modules to get a clean start):

1. Download and install the \[Internationalization\] project.
2. Enable the **Multilingual content** module.

Then add any additional languages you want, but do *not* enable them. This is supposed to add translations for the *Node types*, but this may not happen (due to the bug I mentioned initially).

You can confirm this by looking under the "Overview" tab of the translation interface:

If the percentage in the "Node types" for your second language is ("Norwegian Bokmål" in the image above) is 0%, the translated strings for the Node types has not been imported into the translation interface, and after you enable that language, the English strings will appear since there are no translated strings yet.

However, it should now be possible to add these translation by hand. Navigate to the translate tab of the translation interface, and limit search to Node types.

The strikethrough over the string with the two letters in the Languages column means that the translation is missing. Click "edit" to add the missing translation.

This exact procedure fixed it for me as can be seen from the "Overview" tab below. The percentage for "Node types" for "Norwegian Bokmål" in now 100%.

*After* doing all the above, it is OK to set a non-English language as default.
> 3 votes

---
Tags: nodes, i18n-l10n
---


# Question
Title: How can CSS emulate content display with labels in one column and data in the other?
I have set the Manage Display option to make the field labels `Inline`, given them a fixed width so that all the data is lined up in a column.

```
.field-label-inline .field-label {
  margin-right: 6px;
  text-align: right;
  width: 110px;
}

```

The problem is that when the is long, the data it gets positioned below the label rather stay to the right of the label. I want as though it was a table with the right-aligned labels in the first column and the data in the second column.

Can that be accomplished via CSS?

# Answer
> 0 votes
Field content supposed to live inside div.field-items, so you can set "width" or "max-width" properties to div.field-items. Value of width/max-width should be same as or smaller than parent div.field width minus label width.

---
Tags: entities, theming
---


# Question
Title: How can I simplify the use of flags with Views Bulk Operations?
I have an administrative display (made with views) that lists content that is pending approval.

In the case of my site, approval means flagging with the *approval\_for\_pub* flag (which triggers a custom rule).

VBO allows nodes to be flagged/unflagged all at once by clicking a handy button:

However, upon clicking this button, by default it shows all possible flags and the flag/unflag option:

This is a problem on my site because **some of the people responsible for approval get confused by the names of the flags and select the wrong option.** So, what I would like to do is create a VBO option that, when the button is pressed, automatically **flags** all applicable content with the **approval\_for\_pub** flag.

How can I approach this?

It seems like a small detail, but this step happens several times a day, so the chance of making a mistake is quite high.

# Answer
> 9 votes
Instead of using the "Flag (or unflag) a node" action directly, create new a rules component and show it in your administrative view.

1. Navigate to *Configuration » Workflow » Rules » Components*
2. Click on *Add new component* , choose *Rule* from the components plugin drop-down menu.
3. Choose a name (e.g. Approve), add a parameter with the type node.
4. Add a condition, choose *Node is flagged* from the drop-down menu.
5. Choose the appropriate flag, select the node-parameter for the node, choose site:current-user for the user on whose behalf the flagging-action will be performed, select *negate* such that the condition will evaluate to true when the node is **not** flagged.
6. Add an action, choose *Flag a node* from the drop-down menu.
7. Choose the appropriate flag, select the node-parameter for the node, choose site:current-user for the user on whose behalf the flagging-action will be performed.

Edit your administrative view, configure bulk operations such that the *Approve* operation is shown instead of the *Flag (or unflag) a node*

---
Tags: flags, views
---


# Question
Title: How to Translate Content type name using i18n module?
I am developing a multilingual site that supports English and Norsk bokmal. I have set English as my default language. I wanted to translate the contents and the other things in the site.

My real problem started when I found that I was unable to see the translation of the content type's name. I went to admin/config/regional/translate/translate and translated everything, but still my content type's name is not translated.

I have attached a screenshot of the translation page. Still I don't find a way to translate the content type's name.

# Answer
> 9 votes
First, I must point out that if all you want is a *single language* non-English website you should *not* install the Internationalization project, and *not* enable the **Multilingual content** module (part of the Internationalization project).

If you have this problem with a single-language non-English web-site, all you need to enable the **Locale** module (part of core) and enable the Localization update module. See the first part of this answer to see how to deal with this if you've a problem with content type names not being translated on a *single language* non-English website.

However, if you're creating a *multi-language* website where the user interface and the content shall be in multiple languages (due to various detection and selection strategies), then you need to install a project named Internationalization and enable several of its sub-modules, including one named **Multilingual content**.

However: Do *not* do this if all you want is to have the the site user interface and its content in a single language that is not English. The Internationalization project is (IMHO) hard do configure correctly, and still have some serious bugs unfixed. Do not install it unless it is absolutely required.

*If* you need a *multi-language* website and you've configured it *and* you've configured the language settings *and* already set another *default language* than English, then the names of content types will not be translated by default, even if the translations for the names of these types are already present in the translated strings listed for the built-in interface.

When you enable the **Multilingual content** module, a column named *Node types* will appear in the translate interface overview (if this column do not appear, then the **Multilingual content** module is not enabled). For the names of the content types to appear, you ned to have these translated in the text group *Node types* as well. The recipe below tells you how to do this.

I really think this is a bug in the Internationalization module, and as such is off-topic here. See Translate interface for nodes, fields, etc. show wrong language in the column for the issue.

However, I was able to get the node types translated at my site by doing the following:

First, I made sure that I installed the **Internationalization** module and all the required helper modules (such as **Multilingual content**) *before* I added any languages. I also made sure that I used English as the *default* language all the way during the translation process.

So you do the following with English as the *only* language enabled (if you've got additional languages enabled, uninstall them, you will also need to disable and uninstall the **Internationalization** module and all its helper modules to get a clean start):

1. Download and install the Internationalization project.
2. Enable the **Multilingual content** module (part of the Internationalization project).

Then add any additional languages you want, but do *not* enable them. This is supposed to add translations for the *Built-in interface* and *Node types*. However, to me it looks as if the translations for text group *Node types* is *not* automatically imported when you enable a new language after you enable **Multilingual content**.

You can confirm this by looking under the "Overview" tab of the translation interface:

If the percentage in the "Node types" for your second language is ("Norwegian Bokmål" in the image above) is 0%, the translated strings for the Node types has not been imported into the translation interface. This means that even after you enable that language, the fallback English strings will be used.

However, it should now be possible to add these translation by hand. Navigate to the translate tab of the translation interface, and limit search to Node types.

The strikethrough over the string with the two letters in the Languages column means that the translation is missing. Click "edit" to add the missing translation.

This exact procedure fixed it for me as can be seen from the "Overview" tab below. The percentage for "Node types" for "Norwegian Bokmål" in now 100%.

*After* doing all the above, it is OK to set a non-English language as default.

# Answer
> 4 votes
You'll want to enable **Multilingual content**, one of the i18n submodules. This will add a *Node types* option to the translation interface.

# Answer
> 4 votes
Note that admin/structure/types always displays **untranslated** node type and description whereas node/add displays **translated** node type and description.

Your screenshot shows that you have translated the node type name correctly. Another, maybe more convienient place would be at admin/structure/types/manage/news/translate.

Multilingual content must be enabled, like Patrick Kenny said.

---
Tags: i18n-l10n
---


# Question
Title: How can I create a user account when a node is created?
How can I show the user registration form upon node creation and create a new user when a node is submitted in Drupal 7?

I want this to be done in the Drupal way without writing any code.

# Answer
> 5 votes
You should be able to use Rules for this.

Create a new rule that has *After saving new content* as the Event and then set any conditions that you have (node type etc).

Then in the actions section, add a *Create new entity* condition with the value of *User*

From the next page you set the e-mail address and username of the user account, so you'll probably want to have these as fields on your node type.

# Answer
> 0 votes
You ought to have the ability to utilize Rules for this.

Make another Rule that has After saving new content as the Event and after that set any conditions that you have.

At that point in the actions area, include a Create new entity condition with the value of User

In the next page you set the email address and username of the client account, so you'll likely need to have these as fields on your node type.

---
Tags: forms
---


title: view shows as database overriding code

text:
# Question
Title: view shows as database overriding code
I've created a simple feature to export my custom views. I've downloaded the view and enabled it on the manage features screen. When I look at the view in views it tells me that the database is overriding code. I don't know why as I haven't touched the view since creating the feature. Surely the view should be 'in code'?

# Answer
Even if you don't change anything, it's enough to click the 'Save' button on the views configuration page to make it override the code. You can simply revert the view if you are sure that you didn't change anything.
> 1 votes

---
Tags: views, features
---


# Question
Title: Why drush is not maintained in drupal.org?
Drush project page says, "The Drush project has moved to Github."

I would like to know if there is any specific reason for moving to Github.

# Answer
> 7 votes
The motivation for moving to GitHub is discussed on our wiki page:

> Drupal.org is poor fit for Drush as we get features we don't want on our project page
>
> * Usage statistics (Drush isn't a module and thus can't report usage)
> * Release names must map to a single Drupal version
> * The issue to fix this stuff is nearly five years old.

---
Tags: drush
---