# Question
Title: My product filter only scans the first referenced product on a node
I've got View of Product Displays, each Product Display are referencing 1-4 Products. Each Product are tagged with a Taxonomy Term (attributes).

When I create an Exposed Filter on the Terms it's only scanning the first Product referenced by each Product Display making each Product Display appearing only on one of the terms in the Exposed Filter even though it may reference 3 Products with 3 different Terms. How can I make it scan all Products referenced and hereby display the correct results on my product filter?

Here's my view:

```
$view = new view();
$view->name = 'releases';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Releases';
$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'] = 'New Releases';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['use_more_text'] = 'All releases';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'better_exposed_filters';
$handler->display->display_options['exposed_form']['options']['expose_sort_order'] = FALSE;
$handler->display->display_options['exposed_form']['options']['autosubmit'] = TRUE;
$handler->display->display_options['exposed_form']['options']['bef'] = array(
  'general' => array(
    'allow_secondary' => 0,
    'secondary_label' => 'Advanced options',
    'collapsible_label' => NULL,
    'combine_rewrite' => NULL,
    'reset_label' => NULL,
  ),
  'field_format_tid' => array(
    'bef_format' => 'bef',
    'more_options' => array(
      'bef_select_all_none' => 1,
      'bef_collapsible' => 0,
      'is_secondary' => 0,
      'any_label' => '',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
          1 => 'vocabulary',
          'secondary_label' => NULL,
          'collapsible_label' => NULL,
          'combine_rewrite' => NULL,
          'reset_label' => NULL,
        ),
        'secondary_label' => NULL,
        'collapsible_label' => NULL,
        'combine_rewrite' => NULL,
        'reset_label' => NULL,
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
        'secondary_label' => NULL,
        'collapsible_label' => NULL,
        'combine_rewrite' => NULL,
        'reset_label' => NULL,
      ),
      'secondary_label' => NULL,
      'collapsible_label' => NULL,
      'combine_rewrite' => NULL,
      'reset_label' => NULL,
    ),
    'secondary_label' => NULL,
    'collapsible_label' => NULL,
    'combine_rewrite' => NULL,
    'reset_label' => NULL,
  ),
  'secondary_label' => NULL,
  'collapsible_label' => NULL,
  'combine_rewrite' => NULL,
  'reset_label' => NULL,
);
$handler->display->display_options['exposed_form']['options']['input_required'] = 0;
$handler->display->display_options['exposed_form']['options']['text_input_required_format'] = 'full_html';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '4';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['total_pages'] = '3';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['inline'] = array(
  'field_product_artwork' => 'field_product_artwork',
  'field_related_artist' => 'field_related_artist',
  'title' => 'title',
);
/* Relationship: Content: Referenced products */
$handler->display->display_options['relationships']['field_product_reference_product_id']['id'] = 'field_product_reference_product_id';
$handler->display->display_options['relationships']['field_product_reference_product_id']['table'] = 'field_data_field_product_reference';
$handler->display->display_options['relationships']['field_product_reference_product_id']['field'] = 'field_product_reference_product_id';
$handler->display->display_options['relationships']['field_product_reference_product_id']['required'] = TRUE;
/* Field: Content: Artwork */
$handler->display->display_options['fields']['field_product_artwork']['id'] = 'field_product_artwork';
$handler->display->display_options['fields']['field_product_artwork']['table'] = 'field_data_field_product_artwork';
$handler->display->display_options['fields']['field_product_artwork']['field'] = 'field_product_artwork';
$handler->display->display_options['fields']['field_product_artwork']['label'] = '';
$handler->display->display_options['fields']['field_product_artwork']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_product_artwork']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_product_artwork']['settings'] = array(
  'image_style' => 'large',
  'image_link' => 'content',
);
/* Field: Content: Subscriptions */
$handler->display->display_options['fields']['field_artist_tags']['id'] = 'field_artist_tags';
$handler->display->display_options['fields']['field_artist_tags']['table'] = 'field_data_field_artist_tags';
$handler->display->display_options['fields']['field_artist_tags']['field'] = 'field_artist_tags';
$handler->display->display_options['fields']['field_artist_tags']['label'] = '';
$handler->display->display_options['fields']['field_artist_tags']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_artist_tags']['type'] = 'taxonomy_term_reference_plain';
$handler->display->display_options['fields']['field_artist_tags']['delta_offset'] = '0';
/* 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'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Commerce Product: Release date (field_product_release_date) */
$handler->display->display_options['sorts']['field_product_release_date_value']['id'] = 'field_product_release_date_value';
$handler->display->display_options['sorts']['field_product_release_date_value']['table'] = 'field_data_field_product_release_date';
$handler->display->display_options['sorts']['field_product_release_date_value']['field'] = 'field_product_release_date_value';
$handler->display->display_options['sorts']['field_product_release_date_value']['relationship'] = 'field_product_reference_product_id';
$handler->display->display_options['sorts']['field_product_release_date_value']['order'] = 'DESC';
/* 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(
  'product_display' => 'product_display',
);
/* Filter criterion: Content: Product reference (field_product_reference:delta) */
$handler->display->display_options['filters']['delta']['id'] = 'delta';
$handler->display->display_options['filters']['delta']['table'] = 'field_data_field_product_reference';
$handler->display->display_options['filters']['delta']['field'] = 'delta';
$handler->display->display_options['filters']['delta']['value']['value'] = '0';
/* Filter criterion: Commerce Product: Type */
$handler->display->display_options['filters']['type_1']['id'] = 'type_1';
$handler->display->display_options['filters']['type_1']['table'] = 'commerce_product';
$handler->display->display_options['filters']['type_1']['field'] = 'type';
$handler->display->display_options['filters']['type_1']['relationship'] = 'field_product_reference_product_id';
$handler->display->display_options['filters']['type_1']['value'] = array(
  'record' => 'record',
);
/* Filter criterion: Content: Has taxonomy term */
$handler->display->display_options['filters']['tid']['id'] = 'tid';
$handler->display->display_options['filters']['tid']['table'] = 'taxonomy_index';
$handler->display->display_options['filters']['tid']['field'] = 'tid';
$handler->display->display_options['filters']['tid']['value'] = array(
  0 => '98',
);
$handler->display->display_options['filters']['tid']['expose']['operator_id'] = 'tid_op';
$handler->display->display_options['filters']['tid']['expose']['label'] = 'Has taxonomy term';
$handler->display->display_options['filters']['tid']['expose']['operator'] = 'tid_op';
$handler->display->display_options['filters']['tid']['expose']['identifier'] = 'tid';
$handler->display->display_options['filters']['tid']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['tid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
);
$handler->display->display_options['filters']['tid']['vocabulary'] = 'label_subscriptions';

/* Display: Releases page */
$handler = $view->new_display('block', 'Releases page', 'block');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* 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(
  'product_display' => 'product_display',
);
/* Filter criterion: Content: Product reference (field_product_reference:delta) */
$handler->display->display_options['filters']['delta']['id'] = 'delta';
$handler->display->display_options['filters']['delta']['table'] = 'field_data_field_product_reference';
$handler->display->display_options['filters']['delta']['field'] = 'delta';
$handler->display->display_options['filters']['delta']['value']['value'] = '0';
/* Filter criterion: Commerce Product: Type */
$handler->display->display_options['filters']['type_1']['id'] = 'type_1';
$handler->display->display_options['filters']['type_1']['table'] = 'commerce_product';
$handler->display->display_options['filters']['type_1']['field'] = 'type';
$handler->display->display_options['filters']['type_1']['relationship'] = 'field_product_reference_product_id';
$handler->display->display_options['filters']['type_1']['value'] = array(
  'record' => 'record',
);
/* Filter criterion: Content: Has taxonomy term */
$handler->display->display_options['filters']['tid']['id'] = 'tid';
$handler->display->display_options['filters']['tid']['table'] = 'taxonomy_index';
$handler->display->display_options['filters']['tid']['field'] = 'tid';
$handler->display->display_options['filters']['tid']['value'] = array(
  0 => '98',
);
$handler->display->display_options['filters']['tid']['expose']['operator_id'] = 'tid_op';
$handler->display->display_options['filters']['tid']['expose']['label'] = 'Has taxonomy term';
$handler->display->display_options['filters']['tid']['expose']['operator'] = 'tid_op';
$handler->display->display_options['filters']['tid']['expose']['identifier'] = 'tid';
$handler->display->display_options['filters']['tid']['expose']['required'] = TRUE;
$handler->display->display_options['filters']['tid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
);
$handler->display->display_options['filters']['tid']['vocabulary'] = 'label_subscriptions';
/* Filter criterion: Commerce Product: Format (field_format) */
$handler->display->display_options['filters']['field_format_tid']['id'] = 'field_format_tid';
$handler->display->display_options['filters']['field_format_tid']['table'] = 'field_data_field_format';
$handler->display->display_options['filters']['field_format_tid']['field'] = 'field_format_tid';
$handler->display->display_options['filters']['field_format_tid']['relationship'] = 'field_product_reference_product_id';
$handler->display->display_options['filters']['field_format_tid']['value'] = array(
  16 => '16',
  14 => '14',
  15 => '15',
  21 => '21',
  40 => '40',
);
$handler->display->display_options['filters']['field_format_tid']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_format_tid']['expose']['operator_id'] = 'field_format_tid_op';
$handler->display->display_options['filters']['field_format_tid']['expose']['label'] = 'Filter by format';
$handler->display->display_options['filters']['field_format_tid']['expose']['operator'] = 'field_format_tid_op';
$handler->display->display_options['filters']['field_format_tid']['expose']['identifier'] = 'field_format_tid';
$handler->display->display_options['filters']['field_format_tid']['expose']['multiple'] = TRUE;
$handler->display->display_options['filters']['field_format_tid']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  7 => 0,
  8 => 0,
);
$handler->display->display_options['filters']['field_format_tid']['expose']['reduce'] = TRUE;
$handler->display->display_options['filters']['field_format_tid']['type'] = 'select';
$handler->display->display_options['filters']['field_format_tid']['vocabulary'] = 'shop_format';

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

```

# Answer
> 1 votes
The reason it's only matching against terms from the first referenced product is because you restrict query results to just that product when you added the `Content: Product reference (field_product_reference:delta)` filter. This is limiting query results to just the rows where the referenced product delta is 0 (i.e. the first referenced product).

What you'll need it to figure out how to do is not restrict the query result set (i.e. get rid of that delta filter) but still maintain the look you want when the View is rendered. I can't say for sure this is a good lead, but you might look into grouping the results by node ID if that's possible.

---
Tags: commerce, views
---


# Question
Title: How to refresh/update a Block or View after a form submit?
I have a View of created entities displayed as a block. On the same page I have a form with which new entities can be created, and this form submits through AJAX because I do not want a page reload after submission. The issue of coarse though is that after submission, the View on the same page is not updated which makes it look like that the submit has done nothing. I could set a Rule to reload the page after submission, but I would like the View to update without reload.

**What I have tried (Drupal 7)**

I have experimented with the Views Auto-Refresh module, but constantly refreshing a View seems a bit of overkill since for performance reasons it would be better to only have this triggered on a form submit. The module Views Flag Refresh does exactly what I need but because it is a Flag and not a form element I am not sure how I could use a flag to submit the contents of a form. The following module does exactly what I need and refreshes a View after a form submit, but there is only a D6 version (Ajax Views Refresh) with no plans for a D7 port. The final possibility I have considered is Node.js integration (Views Node.js), but this seems hugely complex for such a small feature and I am not that confident in my ability to pull this off.

So at this point I'm not quite sure in which direction to go. How could I do a refresh after a form submit?

# Answer
> 1 votes
I think this might be the module you are looking for:- https://www.drupal.org/project/views\_nodejs

I has a few dependencies, and you will need to setup a node.js server, but aside from that it's pretty straightforward.

# Answer
> 0 votes
You can create a simple module with hook menu which loaded ajax callback function.

I found some useful tutorial on Youtube: https://www.youtube.com/watch?v=zyLmQtiSXgI

You may find sample source code here: https://github.com/seanbuscay/drupal-ajax-demo

# Answer
> 0 votes
You can write your own ajax (using Drupal Behaviour method) callback to append the updated values to you particular block.

I hope in your block you will be showing title, description and image (if need),

So using your ajax callback you can get submitted data (whatever you want) from the database. Then you can append those values in existing block without refreshing page.

This will give better user experience with less development work.

---
Tags: views, blocks, ajax, forms, updating
---


title: Add role when logged_in

text:
# Question
Title: Add role when logged_in
I want to add a role to the user when they log in for the very first time to their account. Any ideas of how to work this out? Rules maybe?

Thanks,

# Answer
> 1 votes
Rules only with module logintoboggan. Then you will have Event: when user account is active

With custom module hook\_user\_login and you must check for custom fields filled only once like timestamp.

---
Tags: users
---


# Question
Title: Best way to migrate Content from drupal 6 to 7?
Becoming more familiar with Drupal by doing a drupal 6 to 7 upgrade along with switching Ubercart to Commerce. But the site just doesnt seem to work right.

I followed the upgrade procedure suggested by drupal but something is off

Having random errors all over the place, admins running into php memory limit errors(ex. people \> permissions), missing fields, unable to add criteria to views.

Is there a better way to do this. Should I start with a fresh install and import programatically someway or with a a module?

Its a fair amount of content i have to import but would it be better just to do it manually?

Im just wondering how others go about doing this because there seem to be mixed opinions

# Answer
> 1 votes
Migrate might be the module you need:

> The migrate module provides a flexible framework for migrating content into Drupal from other sources (e.g., when converting a web site from another CMS to Drupal). Out-of-the-box, support for creating core Drupal objects such as nodes, users, files, terms, and comments are included - it can easily be extended for migrating other kinds of content. Content is imported and rolled back using a bundled web interface (Migrate UI module) or included Drush commands (strongly recommended).

There is specialized Drupal-to-Drupal data migration for just the task you need:

> migrate\_d2d provides a framework based on the Migrate API for migrating content from Drupal 5, Drupal 6, or Drupal 7 sites into the Drupal 7 site where it is installed. As of the 2.1 release, It requires Migrate 2.6 or later. Besides addressing contemporary needs to migrate to Drupal 7, it has helped serve as a proof-of-concept for incorporating the migration approach into core as an upgrade path (https://groups.drupal.org/imp).

It's far from perfect, all right, but it's good and well tested - in my experience it is most solid way unless you want to write custom one just for your case.

# Answer
> 0 votes
This module can help you: http://drupal.org/project/upgrade\_status, it has a very useful submodule 'upgrade\_assist".

Details from its project page:

> The Upgrade Status module checks the list of projects you have installed and shows their availability for the new version of Drupal core, which can be one of the following:
>
> * Available: A stable release of this project is available.
> * In development: A development release of this project is available, which can be installed for testing purposes.
> * Not ported yet: There are no releases available for this project.
>
> Clicking on any of the modules' boxes will show you notes about upgrading the project, as well as a link to download the new version.

---
Tags: 7, upgrading
---


title: View mode tabs no longer visible

text:
# Question
Title: View mode tabs no longer visible
I added custom display settings on quite a few content types.

>

The view mode tabs disappeared. I tried to uninstall third party modules and rebuild the cache, without luck.

>

What can I try from here? I'm using Drupal 8.0.0-beta15.

# Answer
> 2 votes
The block showing the secondary tab menu was disabled. In order to activate it, I had to pay `/admin/structure/block/list/seven` a visit and manually re-add the `Tabs` block to the `Pre-content` region.

---
Tags: 8, entities
---


# Question
Title: Where does drupal_mail() get the return-path and sender?
I want to send a simple mail using `drupal_mail()`. I don't understand from where it gets sender and incorrect\_mail@gmail.com as return path. From where does it get this email?

```
function rappel_mail($key, &$message, $params) {
  switch($key) {
    case 'informations':
      $message['subject'] = $params['subject'];
      $message['body']= $params['body'];
      break;
  }
}

function my_module_passwordOublie_envoie_password ($email) {
  $response = array();
  global $language;
  $mail_user = user_load_by_mail($email);
  if (!$mail_user) {
    return func_succes(950, $response); // just to check if mail exists
  }
  else {
    $to = 'my.real.email@gmail.com';
    $from = 'noreplay@noreplay.com';

    $params = array(
      'body' => t("hi, you've just received a drupal mail"),
      'subject' => t("test mailing"),
    );
    $message = drupal_mail('rappel', 'informations', $to, $language->language, $params, $from, TRUE);
   }
 }

```

This is Postman response (because I'm working with services on a custom resource that send mail using `drupal_mail()`).

```
"Return-Path": "????@gmail.com", <=== those emails are valid (mine too but i've delete this email every where it was ! )
"Sender": "????@gmail.com",<=========
"From": "noreplay@noreplay.com" <=== good one

```

# Answer
`drupal_mail()` gets the value for those headers either from the the value of the *site\_mail* persistent variable (set in admin/config/system/site-information), or from the *sendmail\_from* setting found in php.ini.

The first line of `drupal_email()` show exactly how the default value for the sender is set.

```
$default_from = variable_get('site_mail', ini_get('sendmail_from'));

```

This is then the code that sets the email headers.

```
  if ($default_from) {

    // To prevent e-mail from looking like spam, the addresses in the Sender and
    // Return-Path headers should have a domain authorized to use the originating
    // SMTP server.
    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from;
  }
  if ($from) {
    $headers['From'] = $from;
  }
  $message['headers'] = $headers;

```
> 0 votes

---
Tags: emails
---


# Question
Title: When to use a tpl.php file instead of a .css file?
This is my first question on Drupal answers, so be kind to me :)

I'm fairly new to Drupal, and indeed web developing in general. I have been working on my first site for a few months now, learning as I go.

In the past month, I have figured out how to make my own sub-theme of the one I was using. I have been using the sub-theme to adjust the "little niggles" that I have with page formatting directly. So far, I have been doing this by adding little snippets of css to a .css file in the sub-theme - and trying to keep this file as DRY as possible.

This has been working well for me, but when reading around, all I see is discussion of modifying/using .tpl.php files, which is making me wonder if I'm missing something and/or setting myself up for major problems as this this .css file grows?

**TL:DR** What are the problems and/or disadvantages of using a single .css file to make styling adjustments on my drupal site?

# Answer
If your real question is more along the lines of:

> Should I make the CSS conform to the markup, or make the markup conform to the CSS?

Then that's just a judgment call, there's no right or wrong answer. Go with what you feel comfortable doing. Some people love the plethora of classes Drupal adds by default, some people hate it. Some people prefer the Bootstrap approach (class, class, class), some people prefer the Susy approach (as few classes as possible, ostensibly). Neither is right or wrong, just different.

Read on for answers to the specific posed questions...

> When to use a tpl.php file instead of a .css file?

The literal answer to that is simply "never".

A CSS file and a template file are for different things, and contain different things. You wouldn't put markup in a CSS file, and you wouldn't put CSS in a template file (except perhaps in rare circumstances like if you were inlining the above-the-fold content or something).

> What are the problems and/or disadvantages of using a single .css file to make styling adjustments on my drupal site?

There are no problems or disadvantages *per se*. It's arguably better to split your CSS into multiple files, simply for modularity's sake, but those are all going to be aggregated back into one when the site goes into production mode anyway (assuming the CSS you're talking about is "every page" CSS; you haven't mentioned otherwise).

Basically go with what feels comfortable, by your organisation's standards, or whatever general advice you find and like about organising CSS files. Drupal doesn't mind how you do it.
> 1 votes

---
Tags: theming
---


# Question
Title: Display Suite and Views - how to troubleshoot why a View content pane is not being applied?
I have a site that uses Entity Reference to link exercises with guitar lessons (these are two content types). I created a view (both content pane and block, identically configured), of display type Display Suite, which filters on exercises, uses a relationship with referenced entity, and contextual filter of content node id which corresponds to the lesson node id. In preview all looks fine,a lesson is displayed as well as its associated exercises, and I saved the view.

In Display Suite I managed the display for exercises and lessons and added the view I created to be managed by Display Suite.

So I thought all would be fine on my site, but when a guitar lesson page is loaded, it only displays the lesson fields as managed by Display Suite, but it does not display the exercises associated with the lesson, which I thought would work based on the view.

Now if under Structure-\>Blocks I attach the block view to Content, then the exercises display with lessons. But I thought Display Suite allows one to not think about blocks and instead use views and content panes to control display. Since the view has a content display type, and since the lesson and exercise content types are configured to display fields in DS-arranged content layouts, why on earth would the content pane view not be displaying?

I am new to drupal and I have no idea how clear I have described this issue, but I can clarify as needed.

Any troubleshooting tips to figure out what is going on?

I also have Page Manager and Panels installed, but I disabled the panels I had created previously and I don't see how Page Manager would be interfering since I don't have it managing any of my pages.

Regards

# Answer
> 1 votes
Unless I'm missing something I think you might be confusing the functionality of Display Suite with that of Panels. Views content pane displays can be accessed from the Panels UI and added to a page but I've never seen that functionality within Display Suite. Are you using any additional modules to add this functionality?

There's various ways you can do this but a really quick and easy approach is to use EVA. Here is it's project page description.

> "Eva" is short for "Entity Views Attachment;" it provides a Views display plugin that allows the output of a View to be attached to the content of any Drupal entity. The body of a node or comment, the profile of a user account, or the listing page for a Taxonomy term are all examples of entity content.
>
> The placement of the view in the entity's content can be reordered on the "Field Display" administration page for that entity, like other fields added using the Field UI module.
>
> In addition, the unique ID of the entity the view is attached to -- as well as any tokens generated from that entity -- can be passed in as arguments to the view. For example, you might make a View that displays posts with an 'Author ID' argument, then use Eva to attach the view to the User entity type. When a user profile is displayed, the User's ID will be passed in as the argument to the view magically.
>
> That's right: magically.

Basically, create an EVA variant of your view, there's a couple of settings to say what entity type (node) and bundle (Guitar lesson) to attache it to. save this and go to the manage display page of your content type and the view will be there.

It will work with Display suite turned on or off.

---
Tags: views, blocks, display-suite
---


title: How do I toggle the update warning?

text:
# Question
Title: How do I toggle the update warning?
I recently used `drush` to update my site. This is the current `drush status`:

```
$ drush status
 Drupal version                  :  7.29
 Site URI                        :  http://default
 Database driver                 :  mysql
 Database username               :  %$^&*(
 Database name                   :  %$^&*(
 Database                        :  Connected
 Drupal bootstrap                :  Successful
 Drupal user                     :  Anonymous
 Default theme                   :  openchurch_theme
 Administration theme            :  seven
 PHP configuration               :  #$%^&*
 PHP OS                          :  Linux
 Drush version                   :  6.4-dev
 Drush configuration             :
 Drush alias files               :
 Drupal root                     :  #$%^&*
 Site path                       :  sites/default
 File directory path             :  sites/default/files
 Temporary file directory path   :  /tmp

```

But when I visit my admin page, I still get the "You need to upgrade" message. How do I get it to stop?

Here is the update screen:

# Answer
> 0 votes
In this particular case, the issue was that Drupal 7.30 had become available, and the UI of the site was reporting that it had 7.28 installed. This was cached by an out-of-date cache, I believe. Everything was resolved when I updated from 7.29 to 7.30.

---
Tags: upgrading
---


title: Display search results in a view

text:
# Question
Title: Display search results in a view
I read everywhere that it is possible with Views 3 to display search results in a custom view by adding a contextual filter "search: term" to the view and pointing the view's path to "search/node/%". There even used to be a module that added this contextual filter to earlier Views versions: https://drupal.org/project/views\_handler\_argument\_search

Also, see #9 here: https://drupal.org/node/266683

However, I don't have any "search" contextual filters or relations in my view. Was this feature removed again?

---

Edit: I don't want to search the view once I'm in the view (exposed filters would be the answer in this case). I want to use a view to display the search results of the search form that would be present anywhere on my website. Also, I want to use the indexing feature of Search module instead of using exposed filters. Unfortunately, Apache Solr is not an option.

# Answer
1. Create a page view called search (Add the fields to display)
2. Add a path "/search"
3. Add the contextual filter "Global: null"
4. Add a filter "**Search: search terms**", expose the filter.
5. Expose the form in a block to use the search form elsewhere on your site.
> 1 votes

# Answer
Have you tried to use "exposed filters"?

You can set it in Filter Criteria and then in the Advance column you can set "Exposed form in a block".
> 0 votes

# Answer
Create a views with "search" path, add your filters in filter section ( don't use contextual filter") then in **advanced ,Exposed form** set **Exposed form in block** to yes then save views, after that the exposed search block will be exist in block list, you can put it in every where you want, when user search something in that block it will redirect to `search?title=keyword` ( or something like this, I supposed here that you search filter is title)
> 0 votes

---
Tags: views, search
---


title: how to log downloaded files

text:
# Question
Title: how to log downloaded files
I have a content type with a (private) file field. Content is protected by a node access module.

I would like to log (in a particular way) when a user is about to download a file.

hook\_file\_download looks like it will do the trick, but on the other hand, its stated purpose is to "control access". I'm letting Drupal Core control access; I just want to log a (successful) download.

Is there a better hook to do this with?

# Answer
> 2 votes
`hook_file_download()` is invoked in two occasions:

* When Drupal is verifying the users have access to the file they are trying to download

```
function file_download_access($uri) {
  return count(file_download_headers($uri)) > 0;
}

```
* When Drupal is returning the headers for the file to download (and then the data for the file to download)

```
function file_download() {
  // Merge remainder of arguments from GET['q'], into relative file path.
  $args = func_get_args();
  $scheme = array_shift($args);
  $target = implode('/', $args);
  $uri = $scheme . '://' . $target;
  if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) {
    $headers = file_download_headers($uri);
    if (count($headers)) {
      file_transfer($uri, $headers);
    }
    drupal_access_denied();
  }
  else {
    drupal_not_found();
  }
  drupal_exit();
}

```

In both the cases, the function invoking the hook is `file_download_headers()`.

```
function file_download_headers($uri) {
  // Let other modules provide headers and control access to the file.
  // module_invoke_all() uses array_merge_recursive() which merges header
  // values into a new array. To avoid that and allow modules to override
  // headers instead, use array_merge() to merge the returned arrays.
  $headers = array();
  foreach (module_implements('file_download') as $module) {
    $function = $module . '_file_download';
    $result = $function($uri);
    if ($result == -1) {
      // Throw away the headers received so far.
      $headers = array();
      break;
    }
    if (isset($result) && is_array($result)) {
      $headers = array_merge($headers, $result);
    }
  }
  return $headers;
}

```

Watching the Drupal code, I cannot assure the hook is always called twice in row, during the same page request; if it were so, you could take the necessary action when the hook is invoked for the second time.

I would rather change the callbacks for `$directory_path . '/styles/%image_style'` (where `$directory_path` contains the value returned from `file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath()`), system/files/styles/%image\_style, system/files, and system/temporary to verify when a file is going to be downloaded, and log what happening.

This is not going to change in Drupal 8, as it doesn't split `hook_file_download()` in two hooks.

---
Tags: 7, hooks, files
---


# Question
Title: Order pending but credit card charged drupal commerce
I am using authorize.net gateway and when I have done test runs myself everything is great. But we had our first order today and was only notified when saw authorize.net charge. The credit card charge went through BUT Drupal commerce shows order as PENDING. and no email is sent, what could this be? Is there a final step they are not completing but still after payment? This is strange.

# Answer
The answer is you need to set the workflow to set the order as completed. Commerce out of the box takes the safe route and assumes nothing about your shopping cart workflow. There is an email that can be configured in Rules for the order confirmation.

The order confirmation email is sent by the rule named `Send an order notification e-mail` that is under the tag `Commerce Checkout` in the Rules UI.

To update the order as completed you will need to create a new rule to set the order as completed based on your business rules. It can be as simple as setting the order as completed upon successful completion of an order.

You can use the event `Completing the checkout process` which will trigger after a successful card charge with Auth.net module or any of the other payment modules, Conditions are none for a simple checkout, actions are `Update the order state`, data selector is `commerce-order` then "Order State" is "Completed".

Here is a visual of the rule:
> 2 votes

---
Tags: commerce
---


# Question
Title: Is there a module that will let me set up site-wide notifications like Stack Overflow's orange one?
I'm looking for a Drupal 7 compatible module that will let me set up site-wide notifications similar to Stack Overflow's orange bar (Welcome to this site, read the FAQ etc.). I haven't been able to find one.

Please note that I don't want to display **system** messages like this, I want something where **I** or other selected users can set up custom ones.

# Answer
> 3 votes
Check out the list of modules for Displaying Status Messages — some of these might provide a good starting point.

# Answer
> 0 votes
Here are some other options:

1. User Alert https://www.drupal.org/project/user\_alert
2. Site Alert https://www.drupal.org/project/site\_alert
3. Alerts https://www.drupal.org/project/alerts
4. Sitewide Alert Message https://www.drupal.org/project/sitewide\_msg

---
Tags: 7, users, notifications
---


# Question
Title: Importing Bootstrap CDN-mediated styles into the Sub-theme's Style.css
I've opened a fresh Bootstrap sub-theme. This sub-theme is empty of any styles. What is the right way to import the CDN-mediated style sheets into the (now-empty) Style.css of the sub-theme?

It's a long story why I don't want to use the Bootstrap CDN in that particular case but I really just want everything to be local.

How could I import the basic Bootstrap Stylesheets into my Sub-theme's Style.css file and finally use everything local?

Thanks,

# Answer
You can use Bootstrap Library module to do that. quoting from the project page:

> This module is fully compatible with the Bootstrap Theme. If you wish, use it as an alterative to the CDN loading.
> 2 votes

---
Tags: theming
---


# Question
Title: Dynamically prepend or append a path element to content urls?
Is there a way I can easily prepend a dynamic element to the beginning of content urls?

For example, I have a `/photos-galleries` Panel/Page which includes a View showing a bunch of photo galleries. I also have `/videos` which similarly shows Videos. Both of these items exist in my main nav menu.

If I let the user browse to `/cats/photo-galleries` then my View uses a contextual filter so it will only show photo galleries tagged with `cats`. That's fine and I have that working.

Let's say one of those photo galleries has the content url `/photo-gallery/kittens-1`

If the user clicks on that link and goes to `/photo-gallery/kittens-1`... then my problem is that the main menu with the `/videos` link no longer has the `cats` "filter" on it. I want that filter type to follow the user along.

So, I'd like to rewrite the links to the content generated by the View so that I can change `/photo-gallery/kittens-1` to `/cats/photo-gallery/kittens-1` that way when the user clicks on that piece of content, I'll still be able to know that I'm filtering my site content according to `cats`.

Does that make sense? Any suggestions on how I can rewrite those urls, based on the current page url, being generated by the view?

Or if it is easier, I can append the `cats` filter tag to the end of the urls and make it `/photo-gallery/kittens-1/cats`. That would be fine also.

**I'm not asking about how to filter the content in the view, I'm asking about rewriting the url of content items generated by that view so that it maintains the same `/cats` filter.**

# Answer
> 0 votes
The hooks that can actually change the links used from Drupal are `hook_url_inbound_alter()` and `hook_url_outbound_alter()`.
I have never used them to alter a link basing on the URL of the currently viewed page, but in the case of `hook_url_outbound_alter()` that should not be difficult, as it would require to use `arg()`; in `hook_url_inbound_alter()`, it would be more difficult, since you would need to be able to understand in which cases you happened a string to the URL. If the added part comes from a vocabulary of taxonomy terms, that would be probably easier, hoping that the taxonomy terms don't cause any conflict with enabled modules.

Appending the term at the end of the URL would avoid conflicts. It would also be easier to understand when a URL has been modified from your module.

---
Tags: 7, hooks, nodes, views
---


# Question
Title: How to access to a field value programmatically when field name is variable?
In my content type I have 4 fields:

* field\_talla\_s
* field\_talla\_m
* field\_talla\_l
* field\_talla\_xl

That's my code, I just need to change the "m" on field\_tallas\_***m*** for my variable ***$size*** in case that my size change to S or L or whatever without having to make an if for each size:

```
$size = 's';
print $node->field_tallas_m['und'][0]['value'];

```

How should it be?

# Answer
> 3 votes
Given your code, you can PHP's curly brace syntax.

See http://php.net/manual/en/language.variables.variable.php

```
<?php
$size = 's';
$field_name = 'field_tallas_' . $size;
print $node->{$field_name}['und'][0]['value'];
?>

```

Note that you should be using `field_get_items` and/or `field_view_value` instead for best practices.

---
Tags: theming
---


# Question
Title: Plugin still uses the old version of Jquery even after hook_js_alter
I have drupal-7.34 installed and Im using Jquery Update 7.x-2.5 to make my plugins work. Everything is working fine until I had use a plugin which needs a more recent version of Jquery(jquery 1.11.2).

I had found out that Jquery Update Module is only limited to Jquery 1.10, which doesnt suffice my plugins need. So what I did is use hook\_js\_alter and uninstalled Jquery Update Module.

```
function myid_js_alter(&$javascript) {
     // Swap out jQuery to use an updated version of the library.
    $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'myid') . '/js/jquery-1.11.2.min.js';
    dsm($javascript);
}

```

After doing so, I got a really mess up interface:

This is because the newer version is added last after the webcam plugins. I found it out by displaying `$javascript` in hook alter.

Below is my hook\_init:

```
function myid_init() {
    //Webcam Plugin
    drupal_add_js(drupal_get_path("module", "myid") . "/photobooth-js-gh-pages/photobooth_min.js");
    drupal_add_js(drupal_get_path("module", "myid") . "/photobooth-js-gh-pages/website/js/script.js");
    drupal_add_css(drupal_get_path("module", "myid") . "/photobooth-js-gh-pages/website/css/page.css");
}

```

How to add the newer version of jquery before the plugins get added? or other way to achieve my goal without breaking drupal's default functionality?

# Answer
> 0 votes
To change the jQuery library used by Drupal 7, you need to implement `hook_library_alter()`, not `hook_js_alter()`.

```
function myid_library_alter(&$libraries, $module) {
  if ($module == 'system' && isset($libraries['jquery'])) {
    // Verify existing version is older than the one we are updating to.
    if (version_compare($libraries['jquery']['version'], '1.11.2', '<')) {
      $libraries['jquery']['version'] = '1.11.2';
      $libraries['jquery']['js']['misc/jquery.js']['data'] = drupal_get_path('module', 'myid') . '/js/jquery-1.11.2.min.js';
    }
  }
}

```

Similar code is used by the jQuery Update module in `jquery_update_library_alter()`.

As side note, you could be interesting in reading Added methods to avoid loading jQuery and related JavaScript libraries on all pages when they are not needed. In short, Drupal 7.36 allows modules to tell Drupal if there is the need to load jQuery; this means `drupal_add_js()` now executes the following code.

```
    // Add jquery.js, drupal.js, and related files and settings if they have
    // not been added yet. However, if the 'javascript_always_use_jquery'
    // variable is set to FALSE (indicating that the site does not want jQuery
    // automatically added on all pages) then only add it if a file or setting
    // that requires jQuery is being added also.
    if (!$jquery_added && (variable_get('javascript_always_use_jquery', TRUE) || $options ['requires_jquery'])) {
      $jquery_added = TRUE;
      // url() generates the prefix using hook_url_outbound_alter(). Instead of
      // running the hook_url_outbound_alter() again here, extract the prefix
      // from url().
      url('', array('prefix' => &$prefix));
      $default_javascript = array(
        'settings' => array(
          'data' => array(
            array('basePath' => base_path()),
            array('pathPrefix' => empty($prefix) ? '' : $prefix),
          ),
          'type' => 'setting',
          'scope' => 'header',
          'group' => JS_LIBRARY,
          'every_page' => TRUE,
          'weight' => 0,
        ),
        'misc/drupal.js' => array(
          'data' => 'misc/drupal.js',
          'type' => 'file',
          'scope' => 'header',
          'group' => JS_LIBRARY,
          'every_page' => TRUE,
          'weight' => -1,
          'requires_jquery' => TRUE,
          'preprocess' => TRUE,
          'cache' => TRUE,
          'defer' => FALSE,
        ),
      );
      $javascript = drupal_array_merge_deep($javascript, $default_javascript);
      // Register all required libraries.
      drupal_add_library('system', 'jquery', TRUE);
      drupal_add_library('system', 'jquery.once', TRUE);
    }

```

---
Tags: hooks, javascript
---


# Question
Title: Profile2 Registration Path module integration with LoginToboggan Non-authenticated role
I have a site where there are 2 independent user roles, *USER\_TYPE\_1* and *USER\_TYPE\_2*. Profile2 RegPath module gives me the two unique registration pages for unique role assignments. With LoginToboggan, all new users get a 3rd type of role, *NON\_AUTHENTICATED*, which is removed after verification.

I'm looking for users to get limited permissions (non-authenticated role) before verification, then more permissions (*USER\_TYPE\_2* or *USER\_TYPE\_2* depending on which registration form they used) after verification.

# Answer
LoginToboggan invokes `hook_user_update()` when it validates an email. It sets the property `$account->logintoboggan_email_validated` to `TRUE` so you can test it upon your own hook invocation. Inside your hook\_user\_update invocation, you can use the profile2 function `profile2_load_by_user($user)` to load the validated user object profile to determine which additional roles need to be set.
> 1 votes

---
Tags: users, authentication-authorization
---


# Question
Title: Removing duplicate content caused by node/nid/talk pages
Recently I installed the talk module, didn't like it and uninstalled it. After removing it I have noticed that I have duplicate content listed under both the node ID and the node id followed by talk.

For instance: The page www.mysite.com/about-us is duplicated at the address www.mysite.com/node/4/talk as are all my pages.

In the talk.module file (which has been removed along with the entire talk module) I notice the line:

> $items\['node/%node/talk'\] = array(

To me this looks like the line of code that created these talk pages, however being that I have removed the entire module, flushed caches etc. I do not understand how these pages still exist. Any help would really be appreciated as I have been working on this now for several days with no answer. Thanks in advance.

# Answer
So `/node/4` is your about page isn't it? you just added a url alias. Which means you can access the same page with `/node/4` or with `/about-us`

To quote Clive from Non-existent URLs in Views 3 in drupal 7

> That's the expected behaviour - Drupal automatically routes you to the 'parent' if it can't find the 'child' part of the URL

when I go to `mywebsite.com/node/1/talk` it displays the `/node/1` content to me; even though, the url in the web browser says `mywebsite.com/node/1/talk`, and I haven't even installed the talk module at all.

Try going to `mywebsite.com/node/4/ijustmadethisup` and you'll see you get displayed `/node/4`

Therefore, this is just the default Drupal behaviour, nothing to do with the talk module.
> 0 votes

---
Tags: uri
---


# Question
Title: Pass $form and $form_state as arguments in hook_menu
I have a javascript code below:

```
$.ajax({
    type: "POST",
    url: "?q=myid_print/update_table",
}).done(function(o) {
    console.log(o);
});

```

It calls a function declared in my hook\_menu:

```
function myid_print_menu()
{
    $items = array();
    $items['myid_print/update_table'] = array(
        'title' => 'ID History',
        'page callback' => 'myid_print_all_submitted_id_callback',
        'type' => MENU_CALLBACK,
    );
    return $items;
}

```

Below is the function being invoked:

```
function myid_print_all_submitted_id_callback($form, &$form_state){
    watchdog('myid_print', 'Wow');
    return $form['table'];
}

```

After looking at my drupal's database, particularly in `watchdog` table, I saw the message `Wow`, which indicates that the function `myid_print_all_submitted_id_callback` has been called but my `$form_table` is not updated. The obvious reason behind this is I did not pass an argument `$form` and `$form_state`. Then, this is what my question is. How will I pass `$form` and `$form_state` arguments? Or any way that I could render `$form_table` invoke by javascript?

# Answer
> 1 votes
If you're using Drupal's form API, it already has support for AJAX built into to it via the #ajax property. For example....

```
function MYMODULE_example_form() {
  //@TODO: various form elments...

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#ajax' => array(
      'callback' => '_MYMODULE_example_form_submit'
    )
  );
  return $form;
}

function _MYMODULE_example_form_submit($form, &$form_state) {
  //@TODO: process submitted form
}

```

The examples module has more examples of this if you'd like to see more of it in action.

---
Tags: forms, routes
---


title: How do I create menu link icons?

text:
# Question
Title: How do I create menu link icons?
I noticed that when I added a new menu link, an icon is now show like groups, events, etc. How do I add an icon for that menu link item?

# Answer
You can use menu icons module to generate icon for the menu item.

> This module allows you to upload an image in the menu-item's configuration form.
>
> After uploading the image, the icon data will be added to the menu link's options array.
>
> When a menu link is goes through the theme layer, it will receive an extra class which by default is used to attach the images as a background image to the corresponding menu item.
> 1 votes

# Answer
I've recently run into a similar issue. I have a bootstrap based theme that comes with FontAwesome icons, so I was hoping to be able to directly use these icons in my menu title without installing a separate module.

For example `<i>fa-home</i>Home` as the menu title would display the home icon before the title "Home", or `<i>fa-user</i>` would only show the user icon without any text. For that I wrote the following theming function:

```
function MY_THEME_menu_link($variables) {
  $element = &$variables['element'];
  $pattern = '/(^<i>)([a-z\-]+)(<\/i>)([\w\s]*)/i';
  if (preg_match($pattern, $element['#title'], $matches) > 0) {
    $element['#title'] = preg_replace($pattern, '<span class="icon"><i class="'. $matches[2] .'"></i></span> ' . $matches[4], $element['#title']);
    $element['#localized_options']['html'] = TRUE;
  }
  return theme_menu_link($variables);
}

```

If you want to do the same with superfish menus, you need to add a different theming function, since superfish menus do not call theme\_menu\_link:

```
function scholarly_lite_superfish_menu_item_link(array $variables) {
  $menu_title = $variables['menu_item']['link']['title'];
  $menu_path = $variables['menu_item']['link']['link_path'];
  $link_options = $variables['link_options'];

  $pattern = '/(^<i>)([a-z\-]+)(<\/i>)([\w\s]*)/i';
  if (preg_match($pattern, $menu_title, $matches) > 0) {
    $menu_title = preg_replace($pattern, '<span class="icon"><i class="'. $matches[2] .'"></i></span> ' . $matches[4], $menu_title);
    $link_options = $variables['link_options'] + array('html' => TRUE);
    // need to pass title without markup to page
  }
  return l($menu_title, $menu_path, $link_options);
}

```

Hope this helps someone else stumbling upon similar configuration.
> 1 votes

# Answer
In your template.php file place this

```
<?php
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $link = menu_item_link($mid);
  $css_id = strtolower(str_replace(' ', '_', strip_tags($link)));
  return '<li id="' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. $link . $children ."</li>\n";
}
?>

```

It'll assign a unique id to each of your menu items, allowing you to attach css to individual menu items. Very handy!
> 0 votes

# Answer
You can use these module to add icon in menu

Menuimage

> When editing a menu link, this module provides a file field to upload an image to associate with a menu item. In the array returned by menu\_link\_load, the fid of the image file is contained in \[options\]\[content\]\[image\]. This may may be passed as a parameter to file\_load to obtain its public:// uri, and further used with either file\_build\_uri or image\_style\_url to populate the src= attribute of an .

Menu\_icon

> This module allows you to upload an image in the menu-item's configuration form.
>
> After uploading the image, the icon data will be added to the menu link's options array.
> 0 votes

---
Tags: routes, media, 7
---


# Question
Title: Change the default value of a checkbox element
I created 7 checkboxes which to be selected by default. To achieve this, I implemented `hook_form_alter()` using the following code.

```
function module_form_webform_client_form_31_after_build($element, &$form_state) {dpm($element);
  $element['submitted']['checkbox7'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox6'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox5'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox4'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox3'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox2'][1]['#checked'] = TRUE;
  $element['submitted']['checkbox1'][1]['#checked'] = TRUE;

  return $element;
}

```

This code works fine for me.

Is there a way to change the default value of all the checkboxes without adding a new line for each new checkbox I could later add?

# Answer
> 1 votes
This code find the checkboxes in the 'submitted' element and check it by default. If you make a screenshot of dsm($element\['submitted'\]) message I can check if this code is correct ^^

```
function module_form_webform_client_form_31_after_build($element, &$form_state) {
  foreach ($element['submitted'] as $key => &$value) {
    if ( $value['#type'] == 'checkbox' ) {
      $element['submitted'][$key][1]['#checked'] = TRUE;
    }
  }
  return $element;
}

```

# Answer
> 0 votes
Can you try the following code?

```
function module_form_webform_client_form_31_after_build($element, &$form_state) {
  foreach ($element['submitted'] as $key => &$value) {
    if (strpos($key, 'checkbox')) {
      $value[1]['#checked'] = TRUE;
    }
  }
  return $element;
}

```

---
Tags: forms
---


title: Exporting image styles in Drupal 7?

text:
# Question
Title: Exporting image styles in Drupal 7?
I know that there is a hook to programmatically define image styles in code but I can't find anyway to export ones that already exist in the database to code?

# Answer
> 5 votes
The best way to do this is almost always by using the features module.

That being said if you do not want to use feature this is how you can do it.

In your module you're going to want to define a hook\_image\_default\_styles().

If you already have a style on the database that you would like to define in this hook the best way to accomplish this is by doing something like

```
$style_name = "name_of_your_style";
$style = image_style_load($style_name);
//$style now has everything you need for your hook_image_default_styles definition.

```

It does has some extra stuff in there that can be removed such as the isid, ieid, and storage keys. You should remove those keys when using hook\_image\_default\_styles.

If you want to find out how other items are exported out the best bet would be to look at the feature module. In there there's a directory call includes. There's going to be a file in there for everything that can be exported out in core. So you can use that for examples on how to export out styles, filters, field, etc.

Hope this answers your question.

# Answer
> 1 votes
As always regarding exporting, features is the way to go.

Features will allow you to export image styles that are defined, like it can export content types views etc.

# Answer
> 1 votes
The imagecache\_actions project has a sub module image\_styles\_admin that offers an export and import function. This works the same like exporting a view or feed using the admin UI. Although in this case you don't need the php module, as it is based on serialization of the image\_style data not processing php code.

---
Tags: 7, hooks, media
---


# Question
Title: Import LinkedIn data (profile information) to user profile in drupal
I want to authenticate via LinkedIn and, after successful login, import basic user profile data into the Drupal user profile. We're currently looking into LinkedIn Integration Module. Unfortunately this module doesn't have a strong support or new developments going. Are there alternatives?

# Answer
That module is the only LinkedIn-specific module that does that; LinkedIn Company API Suite is for company (not individual) accounts and flux LinkedIn API integrates with LinkedIn, but it does not provide any other functionality.

For quick Drupal profile creation, you're better off using one of the many social media login modules that supports LinkedIn (e.g. HybridAuth, Janrain, etc.)
> 1 votes

# Answer
The LinkedIn Integration module provides integration with the LinkedIn API.

It bundles :

* a main module, that does nothing on its own, but provides a few functions other modules can build on.
* a LinkedIn Authentication sub-module, that let users login to a Drupal site using their LinkedIn account.
* a LinkedIn Profile sub-module, that let users display parts of their LinkedIn profile within their user page.
* a LinkedIn Status sub-module, that lets users update their LinkedIn status when creating/updating nodes or comments.
> 1 votes

---
Tags: 7, users, social-network
---


# Question
Title: How to programmatically register a user with Mailchimp API
I have a contact form with a checkbox "Register to the newsletter". If this checkbox is checked, I want to register the email adress (a field in the contact form) to the Mailchimp list, which works fine with the Mailchimp block.

I want to do this in my contact\_form\_submit fonction in my module, but I can't find a way... Does anyone know how to do this ?

Thanks.

EDIT: I use this code :

```
if ($values['newsletter'])
{
    $list = array_shift(mailchimp_get_lists());
    mailchimp_subscribe_user($list, $values['mail'], array());
}

```

This code put the user in the table "cache\_mailchimp\_user" but not in the mailchimp list subscribers, even after I run the Drupal cron manually... Any ideas ?

# Answer
> 2 votes
Drupal 7, Mailchimp module 3.4

```
$list_id = '12345asd'; // use mailchimp_get_lists() and look for 'id'
$email = 'some_email@gmail.com';
if ( mailchimp_subscribe (
    $list_id,
    $email,
    array (
        'EMAIL' => $email,
        'FNAME' => $first_name, // fields in your mailchimp list
        'LNAME' => $last_name,
    ),
    false,
    false
)) {
    drupal_set_message ( t('Thank you. From now you will receive our promo materials'));
} else {
    drupal_set_message ( 'Error occurred while adding your email to subscribe list', 'error' );
}

```

NOTE: If mailchimp will deside that your email is invalid module will only put watchdog error. To grab that error and display you can patch mailchimp.module find function mailchimp\_subscribe\_process and goto approx line 412. and add drupal\_set\_messaga or whatewer you want.

Approach without patching module (but it's too hacky)

```
$list_id = '12345asd'; // use mailchimp_get_lists() and look for 'id'
$email = 'some_email@gmail.com';
if ( mailchimp_subscribe (
    $list_id,
    $email,
    array (
        'EMAIL' => $email,
        'FNAME' => $first_name,
        'LNAME' => $last_name,
    ),
    false,
    false
)) {
    drupal_set_message ( t('Thank you. From now you will receive our promo materials'));
} else {
    // Get last watchdog mailchimp error
    $query = db_select ( 'watchdog', 'w' );
    $query -> fields ( 'w' );
    $query -> condition ( 'w.type', 'mailchimp', '=' );
    $query -> condition ( 'w.timestamp', time() - 10, '>' ); // check for message in last 10 seconds
    $query -> condition ( 'w.message', 'An error occurred subscribing @email to list @list. "%message"', '=' );
    $query -> orderBy ( 'w.timestamp', 'DESC' );
    $query -> range ( 0, 1 );
    $ans = $query -> execute();
    if ( $wd = $ans -> fetchAssoc() ) {
        $wd['variables'] = unserialize ( $wd['variables'] );
        $message = $wd['variables']['%message'];
        // Get only error message
        if ( preg_match ( '#Internal\sServer\sError:(.+)$#si', $message, $m )) {
            $message = $m[1];
        }
        drupal_set_message ( $message, 'error' );
    } else {
        drupal_set_message ( 'Error occurred while adding your email to subscribe list', 'error' );
    }
}

```

# Answer
> 1 votes
Assuming you're using the Mailchimp module, in your submit handler you can use the function mailchimp\_subscribe\_user($list, $email, $merge\_vars, $message = TRUE, $mcapi = NULL) located in the mailchimp.module.

# Answer
> 0 votes
You should pass list id to this function as the first parameter. Not the entire list array. Also in D7 this function is named just mailchimp\_subscribe.

---
Tags: emails
---


# Question
Title: Views, Display Suite - fatal error on allowed memory size - what could be happening?
I am setting up my guitar lessons site which has categories via taxonomy and then lesson and exercise content types. Exercises are in a lesson, via entity reference. I am using Views and Display Suite. When I try to add a taxonomy view so I can list the lessons (along with the exercises therein), I get this:

Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 64 bytes) in /home/user/dev.example.com/sites/all/modules/views/includes/base.inc on line 93

Here is what I did:

I created a view (content pane) for taxonomy terms of type lesson category. The goal is to have a display such as

```
Lesson 1
Lesson 1 Description
    Exercise 1 in Lesson
    Exercise 1 Description
Lesson 2
...

```

The view filters on taxonomy vocab (term Lessons), there is contextual filter on taxonomy id, and relationship Taxonomy term: Content using Category. I posted screen shot.

I chose view mode lessons\_in\_category.

Then I wasn't sure what to do in Display Suite. I went to taxonomy (Lesson) content manage display, and for the lessons\_in\_category view mode I put the lessons in category view in the content. Screen shot attached.

I keep getting the memory error. And seems to me it shouldn't actually be a memory problem. For instance, when I click on a category, it is not like that one category has so much content to generate a memory error. So I have a feeling there is some sort of infinite loop being generated somehow between views and display suite.

Ideas?

# Answer
The PHP memory limit is being exceeded. In your drupal site, go to /admin/reports/status/php and look for "Loaded Configuration File". It should be one of the first 5 columns in the table. In a plain text editor, or a code editor, open the file listed there. In it, search for `memory_limit` and replace the value next to it with, say, \`128M'. Save that file and restart your web server. You may need to increase the memory limit again, if your server still errors out.
> 1 votes

---
Tags: views, taxonomy-terms, display-suite
---


# Question
Title: hook_pathauto_alias_alter() on bulk update
**EDIT: I've found out that this question doesn't make sense.** The problem isn't that the hook is not called during the bulk\_update. The problem is that the code generates unexpected aliases because of the "variable\_set" request, which led me to think that the hook wasn't called. See my answer for the correct code to programmatically set alias patterns.

---

I have created a function to alter the alias for a particular content type when certain conditions are met, using the following code:

```
function HOOK_pathauto_alias_alter(&$alias, array &$context) {

   if(isset($context['data']['node']->field_myfield['und']))
       variable_set('pathauto_node_contentype_pattern', 'something/[node:title]');
}

```

The problem is, when I create a node and save it, it works, but when i try to bulk update the aliases, it doesn't, and the default pattern set from the GUI is used instead.

# Answer
Works as designed (see edited issue summary).

If you need to alter patterns like me, here's what Pathauto's writer said:

> Setting variables in a hook like this is a bad idea, and not to mention, happens too late for it to actually affect the alias being generated. There is an actual hook for you to use instead, you should use that one instead of the alias alter hook.

```
<?php
/**
 * Alter the pattern to be used before an alias is generated by Pathauto.
 *
 * @param string $pattern
 *   The alias pattern for Pathauto to pass to token_replace() to generate the
 *   URL alias.
 * @param array $context
 *   An associative array of additional options, with the following elements:
 *   - 'module': The module or entity type being aliased.
 *   - 'op': A string with the operation being performed on the object being
 *     aliased. Can be either 'insert', 'update', 'return', or 'bulkupdate'.
 *   - 'source': A string of the source path for the alias (e.g. 'node/1').
 *   - 'data': An array of keyed objects to pass to token_replace().
 *   - 'type': The sub-type or bundle of the object being aliased.
 *   - 'language': A string of the language code for the alias (e.g. 'en').
 *     This can be altered by reference.
 */
function hook_pathauto_pattern_alter(&$pattern, array &$context) {
  // Switch out any [node:created:*] tokens with [node:updated:*] on update.
  if ($module == 'node' && ($context['op'] == 'update')) {
    $pattern = preg_replace('/\[node:created(\:[^]]*)?\]/', '[node:updated$1]', $pattern);
  }
}
?>

```
> 0 votes

# Answer
Issue can be with the setting for Url aliases, when you run the bulk update. You need to keep it on the " **Create a new alias. Delete the old alias.** ". SO it will run update your old aliases. Please check if it works for you.
> 2 votes

# Answer
As Sifro said use hook\_pathauto\_pattern\_alter or there is an another way if you want to have custom data in url patterns. Create a token. For me the best way was to use Variables, make it as a token and i18n aware

```
/**
 * Implements hook_variable_info().
 */
function custom_variable_info($options) {

  $variables['support_pattern'] = array(
    'type' => 'text',
    'title' => t('Support Pathauto Variable', array(), $options),
    'description' => t('Variable for custom pathauto variable for taxonomy, "support" vocabulary', array(), $options),
    'required' => TRUE,
    'localize' => TRUE,
    'token' => TRUE, // We'll produce tokens automatically for this on
    );
  return $variables;
}

```
> 0 votes

---
Tags: hooks, path-aliases
---


# Question
Title: Is the a module that will allow me to quickly switch from administrator to user?
Is there a module that will allow me to quickly switch from the administrator view of my site to the user's view?

I currently use Firefox to login as admin and IE to login as a user. This arrangement works, but is very, very slow.

# Answer
You can use masquerade module.

**Part of description :**

> The Masquerade module allows site administrators (or anyone with enough permissions) to switch users and surf the site as that user (no password required). That person can switch back to their own user account at any time.
>
> This is helpful for site developers when trying to determine what a client, logged in as themselves, might see when logged into the site.
>
> The masquerade module is designed as a tool for site designers and site administrators. While masquerading, a field is set on the $user object, and a menu item appears allowing the user to switch back. Database log (watchdog) entries are made any time a user masquerades or stops masquerading as another user.
> 1 votes

---
Tags: 7
---


title: How to switch between user roles

text:
# Question
Title: How to switch between user roles
I have three user roles

1. Merchant
2. Seller
3. End User

**Merchant** has more permissions privileges than **Seller**. **Merchant** can become a **seller** or an **end user**. When i created a user, i assigned all three roles to that user. But when the user is logged in, by default he should only have **Merchant** privileges. But he can switch to **seller** or **End use**r from a drop down. The user will not have all permission privileges (Merchant + Seller + End User) at a time. He will only have a single role at a time. Is there any way to achieve this.

# Answer
There are couple of module available to do this job. Hope this will be helpful

**1. Masquerade**

> The Masquerade module allows site administrators (or anyone with enough permissions) to switch users and surf the site as that user (no password required). That person can switch back to their own user account at any time.

**2. Role Switcher**

> Role Switcher module provides with an option to change role for testing purposes. It creates 'roleswitcher' role and grants it permission to administer permissions which makes possible to switch back to the original role the user had. The module provides a roleswitcher block and a page, /roleswitcher.
> 1 votes

---
Tags: users
---


# Question
Title: Pre-populate field in content from user profile
I'm trying to pre-populate a field in a new piece of content with a country field from a users profile. These are two different Drupal fields, but they are both using the location module so country codes should easily transferred between the two.

I have managed to verify the data from $field\_country\_you\_co\_ordinate\_fo\['und'\]\[0\]\['country'\]), this prints the country code 'gb' as expected.

I can't pull the value into $form\['field\_location'\]. Tried several different chains of array keys based on the previous ticket linked at the bottom. I'm clearly misunderstanding the combinations of keys needed to pull from one variable to another, so any help would be greatly appreciated.

Thanks in advance

```
function perma_boot_form_organisation_node_form_alter(&$form, &$form_state, $form_id) {
  // Only run against newly created node

  if (empty($form['nid']['#value']) && (!isset($form['#node']->op))) {
    global $user;
    $user_fields = user_load($user->uid);

    if (isset($user_fields->field_country_you_co_ordinate_fo['und'][0]['country'])) {
        //print_r ($user_fields->field_country_you_co_ordinate_fo['und'][0]['country']);
        $form['field_location']['und'][0]['country'] = $user_fields->field_country_you_co_ordinate_fo['und'][0]['country'];
    }
  }
}

```

Have been working from the previous example: How to pre-populate fields on a node creation form based on fields from Profile2 module?

# Answer
> 1 votes
Firstly, thanks to all for the help. I followed your advice and configured devel to print $page. Followed the structure of the page and came up with the amended the code:

```
$form['field_location']['und'][0]['country']['#value']

```

Leaving Devel enabled, I can see the value has been set correctly to gb. However, this breaks the google map functionality.

On to the next problem :)

---
Tags: hooks, location
---


title: Disable CKEditor on summary

text:
# Question
Title: Disable CKEditor on summary
When I use the widget "field-type-text-with-summary" with the CKEditor, my summary is shown in the CKEditor-format. Can I prevent this and display the field with the plain-format? Hooking into the form, I haven't found a format for the summary; there is just one for the whole body field.

using CKEditor module.

# Answer
> 2 votes
I believe the easier path is going with WYSIWYG module.

If you want to go with CKEditor, it sets the editor using hook\_element\_info\_alter. It changes the widget for any form element of the type text\_format, in **every** form built with drupal.

I went looking for the pre\_render function CKEditor uses to set the editor up, and figured out a way to prevent it from showing up in summary fields only. First, we'll have to swap the CKEditor pre\_render function for one of our own:

```
function MYMODULE_element_info_alter(&$types) {
  if (!empty($types['text_format']['#pre_render'])) {
    $types['text_format']['#pre_render'] = array_diff($types['text_format']['#pre_render'], array('ckeditor_pre_render_text_format'));
  }
  $types['text_format']['#pre_render'][] = 'MYMODULE_ckeditor_pre_render_text_format';
}

```

Your module **must** run its code after CKEditor, and you better declare it depends on CKEditor in the .info file.

Then copy the `ckeditor_pre_render_text_format` from CKEditor module to your module and change its name to `MYMODULE_ckeditor_pre_render_text_format`. You will notice it already has an if clause that checks whether `$element['summary']` and loads CKEditor for both value and system. Just delete the line that sets it for summary. In version 1.4 (latest stable) the line looks like this:

```
$element['summary'] = ckeditor_load_by_field($element['summary'], $element['format']['format'], FALSE);

```

# Answer
> 5 votes
I solved this for the CKEditor module for Drupal 7 by altering the widget itself using hook\_field\_widget\_WIDGET\_TYPE\_form\_alter():

```
/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 * Set the '#wysiwyg'-attribute to false for the summary fields.
 */
function YOURMODULE_field_widget_text_textarea_with_summary_form_alter(&$element, &$form_state, $context) {
  if (isset($element['summary']) && !isset($element['summary']['#wysiwyg'])) $element['summary']['#wysiwyg'] = false;
}

```

Hope this helps!

# Answer
> 1 votes
Drupal doesn't have an input format for the summary: Both the summary and the body use the same input format.

# Answer
> 1 votes
Rather than use the CKEditor module use WYSIWYG (and place the CKEditor library in the sites/all/libraries directory). It will only apply the editor of choice to a particular input format so you don't need to mess around with disabling the editor on textareas where it's not needed. Using CKEditor with the WYSIWYG module will not apply the editor to the summary (like you want), although it is possible with hooks to add one if needed.

# Answer
> 1 votes
It is odd that the CKEditor module does not have this option. But until that happens, I created a module that inserts a `#wysiwyg=FALSE` via a #process function.

Use the CKeditor plain summary module.

# Answer
> 0 votes
You may be able to implement hook\_form\_alter and use the #wysiwyg parameter with a value of FALSE. I used this in Fill PDF to aid in preventing the WYSIWYG editor from appearing without having to set a separate ignore rule.

See this issue: http://drupal.org/node/285200 \- looks like it's just been re-implemented. I never knew it had been removed!

# Answer
> 0 votes
Might have to take an approach similar to http://drupal.org/project/excerpt, (Drupal 6). Some details from the module's project page:

> Excerpt module allows you to enter a separate excerpt/summary/teaser for a node, which does not have to be a cut off version of the body.
>
> Even though Drupal 6 provides similar functionality, Excerpt is useful for various reasons, for instance, when also using editors like TinyMCE.

Have a look at the hooks used and something might be useful.

---
Tags: 7, wysiwyg, entities
---


# Question
Title: How do I create a page using Views and Drupal Commerce, where every listed term is a search term?
I am setting up a site using Drupal Commerce, for an online medicine store. I need to create a Views display page that displays around 30 product titles, (maybe chosen randomly and) arranged alphabetically. The challenge, however is that each of the displayed titles, when clicked, leads to a search results page, which then displays all products that have the title as part of their name. The display page is similar to the following link:

http://www.progressiverx.com/store/prescription-otc.php

If you will click on any of the displayed medicine names, you will see the search results page that I am talking about.

I am not sure if there is a specific module or some configuration/logic that I can use to achieve the same using Views. Any help will be deeply appreciated. Thanks in advance.

# Answer
Assign taxonomy terms (e.g. Flomax) to products, then display those terms in your view. Clicking on a term displays the term's page, with all its associated products.
> 1 votes

---
Tags: views, commerce
---


# Question
Title: How to add a menu link to a menu programmatically?
I want to add a menu link to a menu programmatically. Here is my code

```
MenuLinkContent::create([
      'title' => 'Example link',
      'link' => ['uri' => 'internal:/node'],
      'menu_name' => 'main',
    ])->save();

```

But it gives me the following error

```
PHP Fatal error:  Call to a member function get() on a non-object in /var/www/drupal8/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php on line 105

```

Is there any way to add menu links to a menu programmatically?

# Answer
> 2 votes
I was using the wrong namespace. Use the following namespace

```
use Drupal\menu_link_content\Entity\MenuLinkContent;

```

and then the following code will work.

```
MenuLinkContent::create([
      'title' => 'Example link',
      'link' => ['uri' => 'internal:/node'],
      'menu_name' => 'main',
    ])->save();

```

---
Tags: routes, 8
---


# Question
Title: How to create a Drupal calendar with 2 digits (day date format) instead of 1?
Does anybody have experience with adding a **0** before the numbers 1 to 9. After this my calendar numbers should all have 2 digits: 01,02,03,04,05,06,07,08,09,10,11...

I have added a new PHP date format ("d") and that should give 01 instead of 1 (according to the PHP manual).

But I don't know how to implement this in my calendar.

# Answer
> 1 votes
At first you should add a date format on that page `admin/config/regional/date-time/formats/add`.

For example this format (`F d, Y`) gives you that result: **September 9, 2015**.

Then you can use it anywhere on your site.

---
Tags: 7, datetime
---


title: Drupal Core Auto Update?

text:
# Question
Title: Drupal Core Auto Update?
Is there a way to update Drupal Core without reuploading files and following the UPDATE.php file? Something similar to how you can update a Wordpress install with a click of a button? I wasn't sure if there is a module that will allow this?

--edit--

I've attempted the "drush up" command per @Enxebre's suggestion.

I installed Drush to my shared host and it seems to be running correctly. The site is still not updating though. I checked for updates and its still at 7.22 instead of 7.23.

I also had to run an update on Drush. Here are my results from the terminal command:

Drush self update:

```
drush self-update
X-Powered-By: PHP/5.2.17
Content-type: text/html

A newer version of drush, 7.x-5.x-dev (2013-Aug-06), is available.  Would you like to back up your current drush, version 4.3-dev, to /home1/munortap/drush-backups/drush/20130912205746 and replace it with the newer release? (y/n): y
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>576</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>576</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>576</b><br />

```

Drush up:

```
[~/public_html/misadventureinc]# drush up
X-Powered-By: PHP/5.2.17
Content-type: text/html

<br />
<b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in         <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>1668</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/output.inc</b> on line <b>34</b><br />
<br />
<b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>1668</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/output.inc</b> on line <b>34</b><br />
<br />
<b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>1668</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/output.inc</b> on line <b>34</b><br />
<br />
<b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in     <b>/home1/munortap/public_html/drush/includes/drush.inc</b> on line <b>1668</b><br />
<br />
<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in     <b>/home1/munortap/public_html/drush/includes/output.inc</b> on line <b>34</b><br />

```

# Answer
> -1 votes
If you like you can use the CMS Updater module to enable automatic Drupal core updates. Find the module on drupal.org here: https://www.drupal.org/project/cms\_updater

If you need more information about the service behind, lokk here: https://cms-updater.com

Excerpt from project page:

> CMS Updater module helps you to keep your Drupal site secure at all times. Right after a new Drupal core release is published, this is recognised by the CMS Updater Service, which in turn will update your Drupal system.
>
> There is no need for intervention on your part – just check your mailbox from time to time, read your PDF update, and see if the automated updates have been successfully completed (or not).
>
> The use of this module requires the **purchase of a CMS Updater licence key for € 29.99 incl. VAT.** This fee covers one year of updates - your subscription will not be automatically extended, although you will be reminded when your subscription is close to expiring. You can buy the licence key directly in your Drupal admin area under /admin/config/system/cms-updater. If you need a hand or more information, visit https://cms-updater.com.

Emphasis on price added for purpose of this answer.

---
Tags: updating
---


# Question
Title: The operators "Is one of etc" not working with exposed filters
The `"Is one of etc"` operators do not seem to reduce the result set on **exposed** filters. So for example if I have all fruits and select only mango and apple with "is one of" - The result set only shows mangoes and apples if I do not expose the fruit filter. But if I expose the fruit filter, it shows all the fruits. My view is based on a search index configured with search API.

Is this expected behaviour or am I missing something?

# Answer
> 1 votes
Expose the filter, then select the fruits that you need to show and then enable the "Limit list to selected items" option, so the dropdown list filter will only show the fruits that you want, not all of them.

---
Tags: views
---


# Question
Title: Dynamically modify number of columns in view, responsive layout
I'm using one of the AdaptiveThemes for a site I'm working on. For the sake of simplicity, we'll say it's a site for set of webseries. On the pages for the episodes, I'd like to have a view that displays thumbnails for each of the other episodes in the series. The view will ideally be setup like Hulu. For example, here, each of the episodes is listed in a slideshow list.

Since the site is responsive, I need to have the number of items displayed change with the size of the window. So, full size might show 4 thumbs, and as the view port gets smaller, it might change to 3 or 2 thumbs at a time. How can I achieve this?

Bonus points if you can give me a hint for scrolling through the list like the hulu site, too. Would that just be an implementation of Views Slideshow?

# Answer
> 0 votes
Clicked on this from the DA active feed, but just spotted it is very old. Hope this is of help to others anyway.

---

You don't need a table, or dynamic changing of columns for this effect.

If I understand correctly, you are just creating a responsive carousel.

There are many out there, but I can recommend Flexslider 2, and it comes with a hand Drupal module too.

Should take you all of 5 min to get working.

# Answer
> 0 votes
I can't see the Hulu link, I'm not in the US, so I can't comment on the slideshow aspect.

I have used Display Suite to create my own layouts and Panels to access the responsive layouts within Adaptive Theme (AT Commerce) because Display Suite layouts are not responsive. I enabled only the core Panels module, trying to do the same with Panels got messy and Display Suite allows you to draw in fields from various sources.

There is a great series of tutorials on using Display Suite here: http://www.youtube.com/playlist?list=PL7E361A55994F1648

You can also use Flexslider to make your images responsive

# Answer
> 0 votes
I have recently installed https://drupal.org/project/footable . Demos can bee seen at http://fooplugins.com/footable-demos/ .

In short it enables you to set columns to appear or disappear depending on the width of the viewport. I think this is what you are trying to achieve.

There are two other modules worth looking at drupal.org/project/responsive\_tables and drupal.org/sandbox/minorOffense/1793630 . Both of these seem promising but are somewhat immature.

# Answer
> 0 votes
You can use the jcarousel module, patched with responsive support, to accomplish what you're looking for.

https://github.com/jmtorres/drupal-jcarousel/tree/develop

The original patch is in the jcarousel issue queue on drupal.org

# Answer
> 0 votes
I have used Views Fluid Grid to do exactly this.

---
Tags: views, theming
---


title: Access to other custom php pages

text:
# Question
Title: Access to other custom php pages
I am new to Drupal, so please bare with me. I have a Drupal site that is working fine. Now what I want to do is allow access to folder which contains some custom php script.

I tried to put the folder in the `/sites/default/files/` but it didn't work. I found a question on it Extending Drupal Functionality to Custom PHP Page but not able to add Drupal functionality on this page. I just want to access that folder and its content.

So please any help would be appreciated. Thanks

# Answer
> 1 votes
The default path or root directory of any Drupal site is the same directory/folder which contains the site itself. ie. Same directory which houses the "sites" directory. If I put a php file there called "my\_code.php", any reference to the file will be seen by everything as default. Its when other directories are created and the file placed there which make a file's location more specfic. So if I'm in a php file in another directory and I put in a statement like:

`include 'my_code.php';`

Drupal will start by looking in its default root directory. If I create a directory there called "my\_php\_files" and put the "my\_code.php" file inside, then my reference to include that file would be:

`include 'my_php_files/my_code.php';`

Default permissions are normally 755 for directories and 644 for files.

---
Tags: navigation, external-scripts
---


# Question
Title: How do I unhook commerce_kickstart_blog_preprocess_node?
I am using Commerce Kickstart 2 with the their blog module, which includes a `hook_preprocess_node()` I need to short-circuit.

I looked at How to "unhook" a hook from a module? and I thought I could put the following in a module.

```
function my_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'commerce_kickstart_blog_preprocess_node' && isset($implementations['commerce_kickstart_blog_preprocess_node'])) {
   unset($implementations['commerce_kickstart_blog_preprocess_node']);
  }
}

```

It doesn't do anything. What am I doing wrong?

# Answer
`$implementations` is an array whose keys are the short name of the enabled modules; `$hook` is the name of the hook, without *hook\_* nor the short name of the module.

You need to change your code to the following one.

```
function my_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'preprocess_node' && isset($implementations['commerce_kickstart_blog'])) {
   unset($implementations['commerce_kickstart_blog']);
  }
}

```

I assume the short name of your module is *my*; if it were *my\_module*, then you would need to use the following code, since the hook is `hook_module_implements_alter()`.

```
function my_module_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'preprocess_node' && isset($implementations['commerce_kickstart_blog'])) {
   unset($implementations['commerce_kickstart_blog']);
  }
}

```
> 1 votes

---
Tags: 7, nodes, hooks
---


# Question
Title: Embed media in Ckeditor field for drupal 7
I'm looking for a plugin for the latest version of CKeditor (3.6.3) so that I can add youtube videos (and other embedded media) to a text area that uses ckeditor.

I found several proposed plugins but most of them are not on the drupal.org site or are simply very old and do not seem to work with drupal 7.

There are a lot of questions on this subject but none that are recent or deal with drupal 7.

I know I can just turn off the rich editor and then embed the code in full html mode but I'd like something simpler for my client. Does such a module exist?

I've also found the media module (that is listed on drupal.org - http://drupal.org/project/media\_youtube) but I don't think it integrates with CKeditor.

To clarify I'm looking for something like this: http://www.fluidbyte.net/embed-youtube-vimeo-etc-into-ckeditor but that works with drupal 7. (This one doesn't seem to work?).

**EDIT**: I am using the standalone CKEditor module

# Answer
The standalone version of ckeditor module comes with a plugin called media embed. Ensure you have:

* Enabled the media embed plugin for Ckeditor
* Added the media embed input filter to a text format that your uses have access to (and is not filtered or tag limited in anyway)
* Added the media embed button to the toolbar for the above text format

And that is it. In order to embed a youtube video (or anything for that matter), you get the `<iframe>` embed code from youtube, and paste it into the media embed dialog popup.
> 6 votes

# Answer
There is different ways to go about this. The easiest way for you would be using Ckeditor youtube.

You could also use the `<iframe>` solution, such as with the following markup.

```
<iframe title="YouTube video player" src="http://www.youtube.com/embed/-J3HfllvXWE" frameborder="0" width="547" height="333"></iframe>`

```

You can use the Media module; see Post YouTube Videos with Media + Media: YouTube.
> 2 votes

# Answer
In Drupal 6 and 7 you can use this module: https://www.drupal.org/project/wysiwyg\_mediaembed which works with the media embed plugin, CKEditor and Wysiwyg module. (I am a co-maintainer and it seems to be working reasonably well for people)
> 0 votes

---
Tags: nodes, files
---


# Question
Title: Truncating text instead of wrapping in a view
I have a view that displays an image, title, star rating and user name of a custom content-type I have created in a grid. When I have a very long title it messes up the layout of the view and makes it look bad as you can see in the below image:

Is there a way I can have long titles like the one below display with only one line and then truncate the rest with an ellipsis. I.E. I would like the first content to have a title of "Very Long title for..." instead of "Very Long title for this project that will wrap to the next line". This doesn't seem possible to do from the site builder, is there a module that might allow you to do this?

# Answer
If you are using Views to do this:

In the `Node : Title` field, there is a setting to limit the number of characters labeled `Trim this field to a maximum length`.
> 4 votes

# Answer
yes, it is, it's under "rewrite results".

But please mark vr3690's answer as the correct one.
> 4 votes

# Answer
You can use the jquery.motrim.js. It will truncate the long text by word and the `div.wrapper` width so it won't cut the long text by number of characters.
> 0 votes

---
Tags: 7, theming
---