# Question
Title: How can I serve a separate CSS file for Internet Explorer?
I am setting responsive design for only IE (Internet Explorer) in Drupal 7.

Is there any method or solution this file is working with only IE not for Firefox and Chrome?

# Answer
> 1 votes
You can either use `drupal_add_css()` with the optional browser type parameter, or go the easier route and use the Conditional Styles module which allows you to add CSS files via your themes info file. First lets use `drupal_add_css()` with the browser type. You should use this in `themename_preprocess_html()` (which goes in your themes template.php file) such as this:

```
<?php
function my_groovy_theme_preprocess_html(&$vars) {
  drupal_add_css(drupal_get_path('theme', 'my_groovy_theme') . '/lte-ie-8.css', array(
    'group' => CSS_THEME,
    'browsers' => array(
      'IE' => 'lte IE 8',
      '!IE' => FALSE
      ),
    'preprocess' => FALSE
  ));
}
?>

```

-Which is of course absurdly complicated just add a conditional CSS file, so I'm not even going to try and explain what all that actually means - you can just play around with the important bit (see the next code snippet) - **the first line is declaring the conditional statement - here this is targeting IE8 or less.** The second line you don't have to worry about, just don't change it.

```
'browsers' => array(
  'IE' => 'lte IE 8',
  '!IE' => FALSE
  ),

```

There is a much easier way to declare conditional stylesheets in Drupal - use the **Conditional Styles** module. This module allows you to declare conditional CSS in your themes info file, just as easily as the very first examples in this article. Just install the module and you can do stuff like this in your themes info file:

```
stylesheets-conditional[lte IE 8][all][] = lte-ie-8.css

```

So that's a basic round up of how to add CSS to your Drupal projects - I hope this helps you get started with Drupal theming a bit easier. If you are building a module please think twice about adding CSS for it - more often than not module CSS is not required, unless you are building something like **Toolbar** or **Overlay** which really demands it. Just let the theme layer handle the style - adding module CSS can often make the themers life that much harder.

# Answer
> 0 votes
Use drupal\_add\_css with the option 'browsers'.

```
drupal_add_css(
  path_to_theme() . '/ie.css',
  array(
    'browsers' => array(
      'IE' => 'lte IE 9',
      '!IE' => FALSE
    )
  )
);

```

You should add this function call in your theme's template.php file through template\_preprocess\_html like this:

```
function MYTHEME_preprocess_html(&$vars){
  drupal_add_css(
      path_to_theme() . '/css/ie.css',
      array(
        'browsers' => array(
          'IE' => 'lte IE 9',
          '!IE' => FALSE
        )
      )
    );
}

```

# Answer
> 0 votes
If you are looking to add the css from a theme and not module, using conditional stylesheets directly in your theme's `.info` file may be preferable to the `drupal_add_css` answer mentioned.

# Answer
> 0 votes
If you are using Zen as your base theme, the conditional stylesheets module should already be included. If not you should download that module.

After downloading and enabling it, it will automatically add the markup in your html.tpl.php file for the ie stylesheets. Be careful, ie only supports this until ie9. ie10+ will need their own stylesheet(s) to work with some css hacks.

Here is a similar post I made a few weeks ago about my issue with it: Need help defining IE specific stylesheet with Zen Starter-kit and Conditional Stylesheet Module

In order to style for ie10 and above, you can currently use an odd media-query target found here: http://www.limecanvas.com/css-hacks-targeting-ie-10/

---
Tags: theming, 7
---


# Question
Title: Show prices excluding Tax/VAT but calculate and display only on checkout
In case of B2B store I need to display all prices **without** VAT taxes. But taxes must be shown on cart and during checkout process. What's the good way for this?

I use commerce\_vat.

# Answer
My solution, all replies/comments are welcomed!

1. Edit rule "***Calculate tax***" *(admin/config/workflow/rules/reaction/manage/commerce\_vat\_calculate)* and add conditions for check if "***Entity has field***": **commerce\_customer\_billing**, **commerce\_customer\_address**
2. For not showing tax on cart (only on checkout): Add condition of type "**NOT Data comparison**": "**Data to compare: \[site:current-page:path\], Operator: is one of, Data value: cart**"
3. Use hook\_commerce\_price\_formatted\_components\_alter() for edit labels (incl./excl. Tax) depending on whether the customer is liable for Tax/VAT or not.

---

Result in checkout process with a customer liable for VAT:
> 0 votes

---
Tags: commerce
---


# Question
Title: How to display field collection items in a chart?
My users have a field collection with 2 fields: 'Points' (integer) and 'Date' (date). I'd like to create a line graph of the 'Points' with the Charts module and use 'Date' as labels. I thought this would be easily achievable with Views, but for some reason, the chart isn't displaying in my view. This is an export:

```
$view = new view();
$view->name = 'linegraph';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'linegraph';
$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['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'chart';
$handler->display->display_options['style_options']['type'] = 'line';
$handler->display->display_options['style_options']['library'] = '';
$handler->display->display_options['style_options']['label_field'] = 'field_date';
$handler->display->display_options['style_options']['data_fields'] = array(
  'field_points' => 'field_points',
  'field_date' => 0,
);
$handler->display->display_options['style_options']['field_colors'] = array(
  'field_date' => '#2f7ed8',
  'field_points' => '#0d233a',
);
$handler->display->display_options['style_options']['width'] = '';
$handler->display->display_options['style_options']['height'] = '';
$handler->display->display_options['style_options']['xaxis_labels_rotation'] = '0';
$handler->display->display_options['style_options']['yaxis_labels_rotation'] = '0';
/* Relationship: User: Points (field_points) */
$handler->display->display_options['relationships']['field_points_value']['id'] = 'field_points_value';
$handler->display->display_options['relationships']['field_points_value']['table'] = 'field_data_field_points';
$handler->display->display_options['relationships']['field_points_value']['field'] = 'field_points_value';
$handler->display->display_options['relationships']['field_points_value']['required'] = TRUE;
$handler->display->display_options['relationships']['field_points_value']['delta'] = '-1';
/* Field: Field collection item: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['relationship'] = 'field_poins_value';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
/* Field: Field collection item: Points */
$handler->display->display_options['fields']['field_points']['id'] = 'field_points';
$handler->display->display_options['fields']['field_points']['table'] = 'field_data_field_points';
$handler->display->display_options['fields']['field_points']['field'] = 'field_points';
$handler->display->display_options['fields']['field_points']['relationship'] = 'field_points_value';
$handler->display->display_options['fields']['field_points']['label'] = '';
$handler->display->display_options['fields']['field_points']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_points']['settings'] = array(
  'thousand_separator' => ' ',
  'prefix_suffix' => 1,
);
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$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;

```

What's going wrong and how can I solve this?

---

This question is part of How to create a line graph of the total user points on a profile page?.

# Answer
> 1 votes
Here is my exported view. It is working fine. Hope that it may help you.

```
$view = new view();
$view->name = 'test_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test view';
$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'] = 'test view';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '3';
$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['style_plugin'] = 'chart';
$handler->display->display_options['style_options']['yaxis_title'] = 'Weight';
$handler->display->display_options['style_options']['yaxis_min'] = '0';
$handler->display->display_options['style_options']['label_field'] = 'field_collection_date';
$handler->display->display_options['style_options']['data_fields'] = array(
  'field_collection_weight' => 'field_collection_weight',
  'field_collection_date' => 0,
);
$handler->display->display_options['style_options']['field_colors'] = array(
  'field_collection_date' => '#2f7ed8',
  'field_collection_weight' => '#0d233a',
);
/* Relationship: Content: Actual mesaurment (field_actual_mesaurment) */
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['id'] = 'field_actual_mesaurment_value';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['table'] = 'field_data_field_actual_mesaurment';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['field'] = 'field_actual_mesaurment_value';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['delta'] = '-1';
/* Field: Field collection item: Date */
$handler->display->display_options['fields']['field_collection_date']['id'] = 'field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['table'] = 'field_data_field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['field'] = 'field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['fields']['field_collection_date']['alter']['strip_tags'] = TRUE;
$handler->display->display_options['fields']['field_collection_date']['settings'] = array(
  'format_type' => 'day_month_year',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
);
/* Field: Field collection item: Your weight */
$handler->display->display_options['fields']['field_collection_weight']['id'] = 'field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['table'] = 'field_data_field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['field'] = 'field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['fields']['field_collection_weight']['settings'] = array(
  'thousand_separator' => ' ',
  'decimal_separator' => '.',
  'scale' => '2',
  'prefix_suffix' => 1,
);
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Author uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'node';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* 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(
  'goal' => 'goal',
);
/* Filter criterion: Date: Date (field_collection_item) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'field_collection_item';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['filters']['date_filter']['operator'] = 'between';
$handler->display->display_options['filters']['date_filter']['exposed'] = TRUE;
$handler->display->display_options['filters']['date_filter']['expose']['operator_id'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['label'] = 'Period';
$handler->display->display_options['filters']['date_filter']['expose']['operator'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['identifier'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
);
$handler->display->display_options['filters']['date_filter']['form_type'] = 'date_popup';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
  'field_data_field_collection_date.field_collection_date_value' => 'field_data_field_collection_date.field_collection_date_value',
);
$handler->display->display_options['filters']['date_filter']['date_method'] = 'AND';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-view';

```

---
Tags: 7, views, entities, userpoints, charts
---


# Question
Title: Fetching more than id's of an entity using EntityFieldQuery
I have just learnt how to use the EntityFieldQuery to make simple queries.

In the example below I fetch all the comment id's for the logged-in-user.

```
global $user;

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'comment')
->propertyCondition('uid', $user->uid)
->addMetaData('account', user_load(1));
$result = $query->execute();
var_dump($result);
$cids = array();
if (isset($result['comment']))
$cids = array_keys($result['comment']);

```

> Is it possible to get the **comment body** and the **node id** where that comment belongs using the way i use above?

# Answer
No - you need to load the comment (`comment_load()`) to get property and field data attached to the results of an EFQ - its job is to load IDs only.

An alternative would be mikeytown2's EntityFieldQueryExtra class, which does allow you to attach field and property data to the results of the query.
> 1 votes

# Answer
To fetch a type of entity you have to add the entity\_type condition to it.

You have to fetch nodes, so the code for it will be as follows:

```
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');

```

The entity condition is set using the function **entityCondition** in which you can set the entity type as node. Once if you have set the entity condition, you can execute the query. The **node ids** are returned in an array in the node key of the result. The complete code to display the nodes will be as follows:

```
$query = new EntityFieldQuery();
    $query
    ->entityCondition('entity_type', 'node');

    $result = $query->execute();
    $nodes = array();
    if (isset($result['node'])) {
      $nids = array_keys($result['node']);
      $nodes = node_load_multiple($nids);
    }

    $list = array();
    foreach ($nodes as $node) {
      $options = array('absolute' => TRUE);
      $url = url('node/' . $node->nid, $options);
      $list[] = '<a href='.$url.'>'.$node->title.'</a>';
    }

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('A block to display results from entityquery'),
      'content' => $content,
    );
    return $block;

```

Thank you.
> 0 votes

---
Tags: 7, database
---


# Question
Title: EntityFieldQuery: number of field values as condition
I have a node type which has a field that can contain an unlimited amount of images.

I want to retrieve a set of entities, but only entities that contain at least one image.

So far this is my query:

```
$result = $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'reference')
    ->propertyCondition('promote', 1)
    ->propertyOrderBy('created', 'DESC')
    ->pager(12)
    ->execute();

```

How should I use the extra fieldCondition to indicate I only want nodes with at least 1 value for field\_images?

# Answer
> 0 votes
Seems like stating the obvious but you need to count the number of values in 'field\_images', then you can set the condition to check that result and make sure it is greater than 0.

There's a good overview of adding expressions and conditions with the `count()` function on this question.

You'll also need to perform a join between 'node' and the table that holds your field values before you make your count, something like this:

```
$query = db_select('node', 'n');
$query->join('field_images', 'fi', 'n.nid = fi.nid');
...rest of query

```

# Answer
> 0 votes
You have to use a **propertyCondition** for this. A code like:

```
$result = $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'reference')
    ->propertyCondition('promote', 1)
    ->propertyCondition('field_images', 1)
    ->propertyOrderBy('created', 'DESC')
    ->pager(12)
    ->execute();

```

-would help. But I don't know whether it works with 'node' 'entity\_type'.

If not, please comment below and/or edit this answer.

Thank you.

---
Tags: database
---


title: Entity form reusable form part

text:
# Question
Title: Entity form reusable form part
I am creating more than 50 entity forms and major parts (contains 20 fields) of these forms are exactly same. Forms are different from each others only one or two field. If I need to edit major and exactly same part of these forms I must repeat editing process for all forms. Are there any aproach to solve this problem? I need edit major part of forms only one time.

# Answer
**Entity forms**, also know as **Reusable forms**, because they are not created directly in the process but in the entity that contains their information, that is, in the **Context** entity.

Now you please take a look at "Reuse of field collection entity type on more than one collection field?", a drupal community question explains something about it(google for it). I hope this would help though.

Thank you.
> 1 votes

---
Tags: entities
---


# Question
Title: How do I get a view to display as themed within a simplenews html email?
I am trying to create a simplenews newsletter, also using Simplenews Scheduler, to weekly send out a newsletter with the content defined by views.

I have a content type set up, and the views defined. I have the views inserted into the content type using Viewfield. This all works fine and the email sends with the views content. However, the styling is not correct.

My views return lists of full nodes which I have set the View Mode of as "Email: HTML". Within the templates in my theme I have added the mark-up I want for the node with that View Mode. When viewing the newsletter on the site (as a node) it all looks correct. However, when I send the newsletter, the email I receive has the view in it's raw format (like that which is displayed in the view preview) and has none of the mark-up I've specified.

How can I get the correct mark-up showing? I don't know if I'm just missing a setting somewhere or something.

Many thanks.

---

My newsletter template (simplenews-newsletter-body--13--email-html.tpl.php) is as follows:

```
<?php /*This appears in the email*/ ?>
TEST NEWSLETTER TEMPLATE
<div>
    <?php /*The following should print the full newsletter node including the views*/ ?>
    <?php print render($build); ?>
</div>
<div>
    <?php /*The following should print a single view*/ ?>
    <?php print views_embed_view('news_upcoming_events','block_1'); ?>
</div>

```

The event node template (node--event.tpl.php) which is returned in the view used in the newsletter template:

```
<?php if($view_mode == 'email_html'){ ?>
    TEST EMAIL TEMPLATE
    <div>
        <h3><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h3>
        <div><?php print render($body); ?></div>
    </div>
<?php }else{ ?>
    NORMAL VIEW
<?php } ?>

```

The newsletter template all appears fine in the email. I see the line `TEST NEWSLETTER TEMPLATE`, but the event node templates are not used in the views output. It is instead some generic drupal/views output.

---

This is the way the view is setup.

And this is the preview displayed with in the view setup. This is also what is appearing in the email when the newsletter is sent, instead of the mark-up declared in my template file. (It is correct when viewing the node on the website though)

# Answer
So it turns out even looping through the view within the template and loading the nodes individually using the nid doesn't work either. Therefore, I needed to find a way to get the view to output with the exact mark-up I require.

The solution I found was using Views PHP. Although thus has performance issues, it is only needed to produce the newsletter which is sent, and so is never experienced by the end user.

I added all the fields I needed in the view and then used a "Global: PHP" field to put it all together with the inline styling I required. This all went within the "Output code" section of the field.

Unfortunately, the available variables don't all work in the Views PHP module and so it is not straight forward to put together, but is possible. An example of my final solution looks something like this:

```
<?php
    //Get the url for the node
    $options = array('absolute' => TRUE);
    $url = url('node/' . $data->nid, $options);
?>
<table style="margin:0; padding: 0; border: 0; outline: 0;border-collapse: collapse;">
    <tbody style="margin:0; padding: 0; border: 0; outline: 0;">
    <?php
        //load the images from the view
        foreach($data->field_field_event_image as $loadedImage){
            $file = file_load($loadedImage['rendered']['#item']['fid']);
            $image = image_load($file->uri);
            $content = array(
                'file' => array(
                '#theme' => 'image_style',
                '#style_name' => $loadedImage['rendered']['#image_style'],
                '#path' => $image->source,
                '#width' => $image->info['width'],
                '#height' => $image->info['height'],
            ),
        );
        print '<tr style="margin:0; padding: 0; border: 0; outline: 0;"><td style="padding:0; margin:0; border: 0; outline: 0;">';
        print drupal_render($content);
        print '</td></tr>';
    }
    ?><tr style="margin:0; padding: 0; border: 0; outline: 0;">
        <td style="padding:10px; border: 0; outline: 0; margin:0;">
            <h3 style="margin: 0;padding:0;font-weight: normal;">
                <a href="<?php print $url; ?>" style="color:#666666;font-size: 1.3em;font-family: Verdana,Tahoma,sans-serif;">
                    <?php print $row->title; ?>
                </a>
            </h3>
            <div style="font-family: Verdana,Tahoma,sans-serif;color:#999999;font-size: 0.9em;"><?php
                foreach($data->field_field_start_date as $date){
                    print $date['rendered']['#markup'];
                }
            ?></div>
            <div style="color: #999999;margin: 5px 0 10px;font-size: 1em;font-family: Verdana,Tahoma,sans-serif;">
                <?php print $data->field_body[0]['rendered']['#markup']; ?>
            </div>
            <div style="text-align: right;">
                <a href="<?php print $url; ?>" style="color:#999999;font-family: Verdana,Tahoma,sans-serif;font-size: 1em;">Read more</a>
            </div>
        </td>
    </tr></tbody>
</table>

```

Newsletter all looks good now and I have already started to send it out. Thanks everyone for their thoughts on the problem.
> 0 votes

# Answer
This sounds very similar to what I did a while ago. I documented my setup on drupal.org. This seems to work for your already. I think your MailSystem is the source of error here. Make sure the MailSystem that is used by Simplenews is using the required style sheets and of course the custom templates from your web theme. Also note, that not all styles that are possible on a website an be used in an email, in fact, only a pretty small subset of styles will work at all.

Take a look at the Emogrifier module, it converts your stylesheets to inline styles for emails. Also, for images and other URLs, the Pathologic module may be of help as it converts relative URLs to absolute ones.
> 1 votes

# Answer
I just gave it a try and can confirm that the newsletter with the embeded view is ignoring the templates that work fine when you view them in the browser. (I don't know why, so maybe raise an help request on their Drupal issue page?)

I tried a view with Full Content nodes and edited the node.tpl.php (like you are trying) and using a Fields view and editing the views-view-fields.tpl.php and neither worked in the sent email (but both worked in the bowser).

**However** \- fields set in the view in the normal way were respected and sent in the email so, a solution is to change your embeded view to use *Fields* instead of *Full Content* and create fields for all the things you want. eg Title, body etc etc.

Overriding the field using Rewrite Results works fine also.
> 0 votes

# Answer
I assume you use Simplenews 7.x-1.x version.

Try to override your `$node->content` using `hook_node_view($node, $view_mode)` instead of template.

Also have a look at `simplenews_build_newsletter_mail()`. And `SimplenewsSourceNode::buildBody()`. If simplenews really send email using these functions, than you can override `simplenews_newsletter_body` theme with `template_preprocess_simplenews_newsletter_body()`.
> 0 votes

---
Tags: 7, views, theming, entities, emails
---


# Question
Title: Save Ubercart order in database, processed through custom payment gateway
I am developing a custom payment gateway module for ubercart, I am able to complete an order on the third party payment system using their api and its working fine, the problem I am facing is how to save that completed order in the database. If we will see in paypal payment gateway for ubercart when we complete an order, Under store option we have an option to view the orders and there status (please check screenshot below), this is the same thing I want to achieve, in-short how can I keep track of orders processed through a custom payment gateway.

I know there is a hook uc\_order\_save($order) in ubercart, but I am confused how to implement it, so that it can interact with the internal values of ubercart orders. I am sure there will be a way in ubercart to achieve it.

# Answer
You do not need to implement that hook.

First you need to be sure whether the payment service method is gateway or redirect. Depending on this, the payment complete function is different.

Within that function, regardless how it is implemented, here is a list of functions that are helpful.

> This function is utilized by the default checkout system and can be used by third party checkout integration modules to complete a sale.

to leave comments in the order regarding the payment outcome, as well as `watchdog()`

> This function logs a payment for an order in the payment receipts table.
> 0 votes

# Answer
Hi I added the below code but still the order is not recorded

function my\_pay\_gateway\_menu() { $items\['paymentcomplete'\] = array( 'title' =\> 'Payment Complete', 'page callback' =\> 'my\_pay\_gateway\_complete', 'access arguments' =\> array('access content'), 'type' =\> MENU\_CALLBACK, ); return $items; }

function my\_pay\_gateway\_complete() {

if (empty($\_POST)) { watchdog('My Payment Gateway', 'Received an empty or incomplete response. Response details: @request\_details', array('@request\_details' =\> print\_r($\_POST,true)), WATCHDOG\_ERROR);

```
return 'There was a problem with your payment';

```

}

if ($\_POST\['status'\] == 'SUCCESS') {

// Assuming all tests passed and payment was successful // Complete the order uc\_payment\_enter($order\_id, 'my\_pay\_gateway', $amount, $order-\>uid, NULL, $orderId);

```
uc_cart_complete($order, variable_get('uc_new_customer_login', FALSE));

uc_order_comment_save($order_id, $uid, $message, $type = 'admin', $status = 1, $notify = FALSE);

uc_cart_empty(uc_cart_get_id());

return 'Thank you for your purchase';

```

} }
> 0 votes

---
Tags: ubercart, payment-gateways
---


# Question
Title: Ctools content types- What do I need to do to get my content to render in the right place?
I have some panels on my site. Previously, I was using custom content panes with the PHP filter to call functions in a custom module. The custom function had lots of `print()` statements and I simply dumped a bunch of HTML to the screen.

Now, I am trying to reform my bad programming practices by moving the custom content panes into Ctools content types. I successfully created a content type, but when I call my function (in my custom module) full of `print()` statements, all of the HTML gets dumped to the top of the page, instead of where the content type has been placed within the panel.

Reading through articles online, it appears this is because the content pane expects me to return something it can render, not directly `print()` the HTML. Is there another PHP function I can use to gather up all the HTML I was previously using `print()` for? What is the correct way to output a bunch of HTML in a ctools content type?

(If this seems obvious, please bear with me. I'm not a programmer by training and I'm probably in a bit over my head.)

# Answer
From the top of my head you should simply be able to do:

```
$pane = new stdClass();
$pane->title = 'Check this out!'; // Optional
$pane->content = '<div>My content</div>';
return $pane;

```

It's also worthwhile to review What are Ctools plugin (content type, access, etc), and how does one create them? which contains an example content type.

The question Correct way to render a modules output through a template? shows an example of rendering through a template, so you can strip the markup out from your pane and have it contain only the relevant content.
> 2 votes

---
Tags: chaos-tool-suite
---


# Question
Title: How can we discover the machine name of $conf keys?
This is part of an interview questions and I am not sure. How can we discover the machine name of $conf keys from standard administrative settings forms by inspecting the DOM? (Assume it is in drupal 7)

# Answer
> 2 votes
By literally looking at the DOM.

For a random example, take the aggregate CSS checkbox on the Performance page:

```
<div class="form-item form-type-checkbox form-item-preprocess-css">
 <input type="checkbox" id="edit-preprocess-css" name="preprocess_css" value="1" class="form-checkbox">
 <label class="option" for="edit-preprocess-css">Aggregate and compress CSS files. </label>
</div>

```

You'll find the machine name for the variable in the `name` attribute of the associated `<input>` element. In this case, `preprocess_css`.

---
Tags: 7
---


# Question
Title: "global" keyword does not work from within drush script
I have the following script:

```
<?php

$GLOBALS['foo1'] = "foobar1";
function g1() {
    echo "g1 " . $GLOBALS['foo1'] . "\n";
}

$foo2 = "foobar2";
function g2() {
    global $foo2;
    echo "g2 " . $foo2 . "\n";
}

g1();
g2();

```

Running it on the browser gives me:

```
g1 foobar1
g2 foobar2

```

Running it via `drush scr example.php` gives me:

```
g1 foobar1
g2

```

Any idea why the `global` keyword doesn't work when I run the script via drush?

I run this on a D7 site with PHP 5.3.5.

# Answer
> 1 votes
To solve it I had to add `global $foo;` before declaring `$foo`.

I suppose it relates to this: http://php.net/manual/en/language.variables.scope.php#98811

---
Tags: 7, drush
---


title: Add content to same page drupal 8

text:
# Question
Title: Add content to same page drupal 8
I got a drupal 8 home page wich works fine but all my content on that page is in the same textbox like this image here:

How can I make it so I can seperate this content and still show it under each other on the home page? This makes it way easier to edit and add new content to the page instead of editing this huge textbox of html code I got now.

I just want it so you can just press the "add content" button and it adds a new html section to the page where you can create a image slider or something and this stacks up under the content that allready has been added.

If i press the add content now it creates a new node/# page wich I dont want. I just want the content on the home page if i press the add content button there.

# Answer
> 1 votes
Just create "promoted to the front page" nodes and keep `node` as your front page. The "add content" button you wanted is the `node/add` page. This has always worked with Drupal stretching back many years.

---
Tags: nodes, 8
---


title: Simple Custom Block

text:
# Question
Title: Simple Custom Block
So I am trying to create a block to list the cities of the scrapyards in the system and i've followed some tutorial and i'm not even getting the block to show up in the list.

I have dir created at: `/sites/all/modules/list_city` and inside that I have the necessary .info and .module files.

The info file contains this:

```
name = List City Module
description = List the scrapyard cities
core = 7.x

```

And the module file contains this:

```
<?php
/**
 * Declare what blocks are provided by this module.
 * Implements hook_block_info().
 */
function list_city_block_info(){
  $blocks = array();
    $blocks['list_city'] = array(
      'info' => t('My Custom Block'),
  );
  return $blocks;
}

/**
 * Define what our block is going to look like.
 * Implements hook_block_view().
 */
function list_city_block_view($block_key){
  $block = array();
    if($block_key == 'list_city'){
      $block['subject'] = t('Marty McFly Countdown');
      $block['content'] = t('Marty will arrive in ').(strtotime("2015-10-21")-time()).t(' seconds.');
    }
  return $block;
}
?>

```

I'm not sure what I am doing wrong. The tutorial says it should show up in the lost of blocks but i'm not seeing it.

Also how could I go on to just list `field_city` of the scrapyard node.

Linking me to some page won't help much because at the minute i've looked at 10+ websites with tutorials on how to create blocks and i'm having no luck at all

EDIT: I've looked at a simpler tutorial and i'm now trying to use this updated code

# Answer
> 2 votes
The following worked for me:

listcity.info

```
name = List City Module
description = List the scrapyard cities
core = 7.x

```

listcity.module

```
/**
* Implements hook_block_info().
*/
function listcity_block_info() {
  $blocks['listcity'] = array(
    'info' => t('List City'),
  );
return $blocks;
}

```

Make sure that you enable the module. (I've forgotten to do this before)

In your code sample there is a closing php tag ?\> This shouldn't be in the module file.

---
Tags: blocks
---


title: How do I render a template?

text:
# Question
Title: How do I render a template?
I am trying to render a template in Drupal 8. In Drupal 7, I would implement `hook_theme()`, make a templates directory in my module, drop the template file in that directory, and I could display it with `theme()`.

What's the equivalent in Drupal 8?

I tried the following code, but it doesn't work.

```
/**
 *  Implements hook_theme().
 */
function twitter_pull_theme($existing, $type, $theme, $path) {
  return array(
    'twitter_pull_tweet_listing' => array(
      'variables' => array(
        'description' => array(),
      ),
      'template' => 'templates/twitter_pull_tweet_listing',
    ),
  );
}

```

Inside the twitter\_pull/templates directory, there is the twitter\_pull\_tweet\_listing.html.twig template file.

This is the code used from the block.

```
$tweet_template = array('#theme' => 'twitter_pull_tweet_listing', '#attributes' => array('params' => $params));
$output = drupal_render($tweet_template, array('params' => $params));
print $output;

```

I get the following error in the log.

> User error: "content" is an invalid render array key in Drupal\Core\Render\Element::children() (line 89 of C:\xampp\htdocs\drupal\core\lib\Drupal\Core\Render\Element.php).

> Twig\_Error\_Loader: Unable to find template "modules/custom/twitter\_pull/templates/templates/twitter\_pull\_tweet\_listing.html.twig" (looked into: C:\xampp\htdocs\drupal). in Twig\_Loader\_Filesystem-\>findTemplate() (line 202 of C:\xampp\htdocs\drupal\core\vendor\twig\twig\lib\Twig\Loader\Filesystem.php).

I imagine this error is caused by not using namespaces and autoloading correctly.

I am not sure I put the template file in the correct directory. Based on the error message, I even tried to put it at C:\xampp\htdocs\drupal\templates\ but it still didn't work.

# Answer
In general, in Drupal 8 you should leave out the *template* line and name the template the same as your hook, converting the underscores to dashes. This was changed because templates are the default output format for themeable output in Drupal 8. In your case the following code in `hook_theme()` would point to the templates/twitter-pull-tweet-listing.html.twig template.

```
/**
 *  Implements hook_theme().
 */
function twitter_pull_theme($existing, $type, $theme, $path) {
  return [
    'twitter_pull_tweet_listing' => [
      'variables' => [
        'description' => [],
      ],
    ],
  ];
}

```

The relevant change record is 'template' is now the default output option for hook\_theme().

From a block or controller, please return a render array instead of a string. In that way, the output can be manipulated afterwards and the raw data is still accessible down the line. In other words, avoid calling `drupal_render()` from your code whenever possible. This applies to Drupal 7 as well. See Render arrays overview / Creating Content As Render Array.

In your block, you should return the following array.

```
return [
  '#theme' => 'twitter_pull_tweet_listing',
  '#description' => 'foo',
  '#attributes' => [],
];

```
> 28 votes

---
Tags: theming, 8
---


# Question
Title: Dealing with compressed JSON string from external API
I'm trying to call the Stack Exchange API but it sends **compressed JSON strings** and I can't uncompress it.

```
$request = drupal_http_request('https://api.stackexchange.com/2.2/users?order=desc&sort=reputation&site=stackoverflow');
$uncompressed = gzinflate($request->data);
$json_response = drupal_json_decode($uncompressed);

```

I'm getting an error like this: `Warning: gzinflate(): data error in adventure_profile_profile() (line 104 of /home/justine/www/adventure/sites/all/modules/custom/adventure_profile.module).` (where line 104 is `$uncompressed = gzinflate($request->data);`).

Am I doing something wrong?

# Answer
> 1 votes
Ok, I'm sorry I just figure it out. I wasn't looking at the `$request->headers` to see what method to uncompress I have to use. Here is the solution:

```
$request = drupal_http_request('https://api.stackexchange.com/2.2/users?order=desc&sort=reputation&site=stackoverflow');

if (isset($request->headers['content-encoding'])) {
  if ($request->headers['content-encoding'] == 'gzip') {
    $request->data = gzinflate(substr($request->data, 10));
  }
  elseif ($request->headers['content-encoding'] == 'deflate') {
    $request->data = gzinflate($request->data);
  }
}

$json_response = drupal_json_decode($request->data);

```

---
Tags: 7
---


# Question
Title: View with relationship in field collection
I have a contentype „roomtype“ with the fields „title“, „image“ and „text“. And i have a contenttype called „pricelist“ containing a multivalue fieldcollection which contains the fields „roomreference“ and „price“; it is multivalue because you can add prices for low- and peakseason; there are multiple nodes of type „pricelist“ since pricelists for the years 2014, 2015, 2016 are online simulatneously. Now i want a view showing me „image“, „text“ and the seasonal prices for every roomtype. The layout should look like this:

```
Roomtype #1
<title>
<image>
<text>

Year 2014
<prices peak season>
<prices low season>

Year 2015
<prices peak season>
<prices low season>

Roomtype #2
<title>
<image>
<text>

Year 2014
<prices peak season>
<prices low season>

Year 2015
<prices peak season>
<prices low season>

.
.
.

```

I was not able to figure out the right configuration of my view, somehow the necessary relationshipping and grouping combined with the a fieldcollection seems to be a challenge for me, i am confused where to start.

# Answer
This sounds like it could be easily done with the Display Suite module. I would use 3 views on 1 page using the main filter on RoomType. Then use DS as needed to output the ordering of fields you want. You might be able to use field\_group with DS to more easily theme the whole page.
> 0 votes

---
Tags: views, entities
---


# Question
Title: How to create dynamic multi column forms using native form module?
I am looking to find out how I can create a form which the definition of the form is coming from a REST API as a JSON object. The form can be 1 column, 2 columns or 10 columns.

I have been able to do this by just using the native table theming option, but I want to be able to do this with the native form options so that I can utilize all the validations and everything else etc.

Does anyone have an idea as to how I can accomplish a multi-column dynamic form?

Thanks in advance!

# Answer
> 1 votes
The way you group form items (as you will need to do to create a single column) is to use the FAPI grouping mechanism, which is described here :

https://www.drupal.org/node/262758

then you can use a loop and some vars to name them, for example :

```
<?php

  // How ever many columns your rest callback wants to make.
  $col_limit = 10;

  for ($x = 0, $x < $col_limit, $x++) {
    $form["group_$x"] = array(
      '#type' => 'fieldset',
      '#title' => t('Your Name'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form["group_$x"]["first_name_$x"] = array(
      '#type' => 'textfield',
      '#title' => t('First Name'),
    );
    $form["group_$x"]["last_name_$x"] = array(
      '#type' => 'textfield',
      '#title' => t('Last Name'),
    );
  }

  $form["col_limit"] = array(
    '#type' => 'hidden',
    '#value' => $col_limit,
  );

?>

```

Will create 10 groups, with form items. You can then use CSS or jQuery to create columns or tabs or format how ever you wish.

The hidden variable is there to tell you submit handler how many coumns there are and therefore how many times it has to loop looking for

```
$form_state['values']["last_name_$x"]

```

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


# Question
Title: Colorbox plugin installed but status report is not recognizing it
I have installed the Colorbox plugin version 5.1.14 in /sites/all/libraries/colorbox but on the status report page I get the following:

> You need to download the Colorbox plugin and extract the entire contents of the archive into the sites/all/libraries/colorbox folder of your server.

# Answer
Drupal needs to have a v in front of the version number:

Original code in jquery-colorbox-min.js

```
/*!
    Colorbox 1.5.14
    license: MIT
    http://www.jacklmoore.com/colorbox
*/

```

Changed to:

```
/*!
    Colorbox v1.5.14
    license: MIT
    http://www.jacklmoore.com/colorbox
*/

```

jedsmith13 https://www.drupal.org/node/1074474#comment-9138455
> -1 votes

# Answer
Sometimes what happens with these libraries is that the download you get from the library site (colorbox in this case) packages its code in a folder itself. For the master download of colorbox, for example, the code comes in a folder called colorbox-master. If you unpack it into

sites/all/libraries/colorbox

then the code ends up in

sites/all/libraries/colorbox/colorbox-master

What you may need to do is unpack it into

sites/all/libraries

and then rename

sites/all/libraries/colorbox-master

to be

sites/all/libraries/colorbox
> 3 votes

---
Tags: javascript
---


# Question
Title: How can I add a captcha to this HTML form
I wanted to add a captcha box to this form. The past developer added this form as html within the content editor.. how can i integrate the captcha to this form? I'm relatively new to drupal and work in wordpress but i am not sure how i can integrate the drupal captcha feature to this form.

```
    <form action="#" method="post">
        <p>Name:
            <input id="Name" type="text" name="Name" />
        </p>
        <p>Email:
            <input id="Email" type="text" name="Email" />
        </p>
        <p>Phone:
            <input id="Phone" type="text" name="Phone" />
        </p>
        <p class="antispam">Leave this empty:
            <input type="text" name="url" />
        </p>
        <p>How Can We Help?
            <br />
            <textarea id="Message" name="Message" rows="4" cols="30"></textarea>
        </p>

        <div class="home-submit-link">
            <input id="submit" type="submit" name="submit" value="Submit" />
        </div>
    </form>

```

# Answer
> 2 votes
I'd say you have two obvious choices :

* either you reimplement the form using the drupal webform module and then add some captcha module like recaptcha,
* or you keep going the tought html-only route and just see how you can integrate a captcha library within your "html within the content editor" form...

I'd say the first strategy is wiser. Particularly since your form is fairly straighforward.

---
Tags: forms, captcha
---


# Question
Title: How do you pass more than one node to a route?
I am working on converting a drupal 7 site to drupal 8 for some practice with 8. In my drupal 7 site, I have a custom hook\_menu declaration with the following:

```
function solution_menu() {
  $items = array();
  $items['solution/%node/%node/%node'] = array(
    'title' => '',
    'page callback' => 'solution_build_solution',
    'page arguments' => array(1,2,3),
    'access callback' => 1,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function solution_build_solution($solution_node, $species_node, $problem_node) {
   //build solution
}

```

I am trying to accomplish the same thing in drupal 8 with a route. However, if I try something like the following i get an error:

```
wlh_decision.solution:
  path: '/solution/{node}/{node}/{node}'
  defaults:
    _content: '\Drupal\wlh_decision\Controller\SolutionController::displaySolution'
    _title: 'Solution:'
    _title_callback: '\Drupal\wlh_decision\Controller\SolutionController::solutionTitle'
  requirements:
    _permission: 'access content'

```

The error i get is:

```
LogicException: Route pattern "/solution/{node}/{node}/{node}" cannot reference variable name "node" more than once. in Symfony\Component\Routing\RouteCompiler::compilePattern() (line 106 of /Users/brianwilliams/Sites/MAMP/drupal8/core/vendor/symfony/routing/Symfony/Component/Routing/RouteCompiler.php).

```

but if i change it to use names other than node, I don't get the autoloading.

Anybody know how I am able to handle this?

# Answer
> 9 votes
You can specify the upcast type for parameters manually:

```
wlh_decision.solution:
  path: '/solution/{solution_node}/{species_node}/{problem_node}'
  defaults:
    _content: '\Drupal\wlh_decision\Controller\SolutionController::displaySolution'
    _title: 'Solution:'
    _title_callback: '\Drupal\wlh_decision\Controller\SolutionController::solutionTitle'
  requirements:
    _permission: 'access content'
  options:
    parameters:
      solution_node:
        type: entity:node
      species_node:
        type: entity:node
      problem_node:
        type: entity:node

```

See Using parameters in routes for a slightly more in-depth explanation.

---
Tags: 8, routes
---


title: Entity form in ctools modal

text:
# Question
Title: Entity form in ctools modal
I'm trying to add an entity form in Ctools popup. I'm using this module https://www.drupal.org/sandbox/andreymaximov/2058521 . My entity form path is like this eform/submit/quote

module docs say use this as link

modal\_forms/%ctools\_js/eform/submit/%entityform\_empty

I'm really lost how to put my quote entity form here according to that link.

# Answer
I recommend trying to use Ctools Automodal module. It's really easy to use just look at the project page:

> Provides automatic modal support for any hook\_menu() paths that have 'modal' =\> TRUE defined. This makes it easy to add optional modal support in any contrib module and helps reduce the burden on module developers to support modals.
>
> Example Usage

```
<?php
function mymodule_menu() {
  $items['mymodule/form'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_form'),
    'access arguments' => array('administer mymodule'),
    'modal' => TRUE, // This line is where the magic happens.
  );
}
?>

```
> 0 votes

---
Tags: 7
---


# Question
Title: Drupal 7 cron does not run civicrm Scheduled Jobs
I'm using Drupal 7, and set the cron job to run every hour.

However, when drupal cron runs, my CiviCrm schedule jobs does not run. These schedule jobs run only when I click the link "run all scheduled jobs manually".

Is there any way I can configure drupal cron job to run CiviCrm schedule jobs too?

Or I need to install any additional module, or configure setting so that the CiviCrm schedule jobs can run automatically?

# Answer
You should configure a separate cron entry for CiviCRM on your server. CiviCRM's Managing Scheduled Jobs is the reference documentation here.

Best practice is to run your CiviCRM cron separately.

* Many CiviCRM tasks (eg delivering large email runs) are not suited to Drupal's typical cron schedule.
* Running CiviCRM cron from Drupal means that an issue with another Drupal module timing out or causing cron to fail may prevent CiviCRM tasks running.
* Likewise, running CiviCRM cron from within Drupal might prevent other Drupal cron tasks firing if CiviCRM cron timed out or failed.

While it may be possible to configure Drupal to run CiviCRM's cron (eg CiviCRM Cron or Elysia Cron modules), I wouldn't recommend that approach.

Things to check when debugging CiviCRM cron -

* Are you calling cron from the same user account that your webserver runs as? CiviCRM cron tasks may write access to the `templates_c/` directory and can fail if called as a user which can't write there.
* Do the tasks execute when called from the CiviCRM Scheduled Tasks page? Visit `civicrm/admin/job?reset=1` then click *More \> Execute Now*
* Is there output from the PHP command to execute CiviCRM cron? If so it may indicate errors. Use `su` to assume the user account your webserver runs as when doing this.

Since we use Drupal extensively with CiviCRM, we fire most site crons using

```
drush -u 1 @example.org civicrm-api job.execute auth=0 --out=json

```

where @example.org is a configured alias for the site in question.

We call CiviCRM cron frequently (max wait for a site is a few minutes) to reduce wait time and avoid queue buildups.

A cron entry for a site *might* look like this in `/etc/cron.d/civicrm`

```
MAILTO=webmaster@example.org
*/7 * * * *    www-data    drush -u 1 @example.org civicrm-api job.execute auth=0 --out=json

```

... but you'll need to adjust this for your environment. You might want to call specific tasks frequently and others once a week; you definitely would need to check the user, Drush alias, and path to Drush shown above!

We also route our cron output to syslog for analysis, but that's well outside the scope of this. CiviCRM cron doesn't set the Drush output status (`drush_log()`'s `$type` parameter) as other Drush commands do.
> 8 votes

# Answer
The recommendation is to fire CiviCRM's cron for Scheduled Jobs directly from your server's cron job configuration:

*Manual:*

> Scheduled jobs: These jobs must be triggered by a cron that runs regularly on your web hosting server.

*Wiki:*

> Managing Scheduled Jobs: However, for most sites it is best to run the required jobs from the server command line, often as one or more automatically scheduled "cron" jobs.

There is a module out there, however, which aims to tie it into Drupal's cron: CiviCRM Cron. I haven't used it but it looks like what you are after, especially if you can't set the cron up on the server level.

> Use Drupal's cron to call CiviCRM's cron. CiviCRM's cron can (and should) be called directly from the command line, but this is a simple way to define the user, pass, and sitekey used in the CiviCRM url and call CiviCRM's cron when it's not possible or convenient to configure CiviCRM's cron.
> 3 votes

# Answer
You might want to try the Elysia Cron module.

It will give you much more control over what cron jobs run and when. Its possible your cron job is timing out before it completes all of its jobs. You could use this module to configure your Civicrm cron job to run at a different time from other cron jobs.
> 1 votes

---
Tags: cron, civicrm
---


title: .info styles load before base theme

text:
# Question
Title: .info styles load before base theme
I have a base theme and a sub-theme. The sub-theme specifies a single styles.css in the \*.info file. The base theme provides CDN css stylesheets, via this hook:

```
function MYTHEME_preprocess_html(&$css) {

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/pure-min.css', array(
    'group' => CSS_THEME,
    'preprocess' => FALSE
  ));

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/grids-responsive-old-ie-min.css', array(
    'group' => CSS_THEME,
    'browsers' => array('IE' => 'lte IE 8'),
    'preprocess' => FALSE
  ));

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/grids-responsive-min.css', array(
    'group' => CSS_THEME,
    'browsers' => array('IE' => 'gt IE 8'),
    'preprocess' => FALSE
  ));

  drupal_add_css('http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css', array(
    'group' => CSS_THEME,
    'preprocess' => FALSE
  ));

}

```

The resulting HTML is this:

```
<style type="text/css" media="screen">@import url("http://mysite.local/sites/all/themes/mytheme/styles.css?nezret");</style>

<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css?nezret" media="all">

<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/grids-responsive-min.css?nezret" media="all">

```

I need the @import to come in dead last in rendered order -- otherwise it seems the base theme styles are overriding my theme specific styless...

I have tried to correct this in the sub--theme by doing:

```
  function MYTHEME_css_alter(&$css) {

    foreach($css as $key => $value) {
      if($key == 'sites/all/themes/MYTHEME/styles.css') {
        $css[$key]['weight'] = 1000;
      }
    }

    uasort($css, 'drupal_sort_weight');

  }

```

This fixes the array but not the rendering order...WTF am I missing or doing wrong???

# Answer
I would be curious to hear a alternative solution but this works too (albeit hackish):

I removed the reference to the stylesheet in \*.info and simply added the call inside template.php:

```
function MYTHEME_preprocess_html(&$vars) {
    drupal_add_css(path_to_theme().'/styles.css', array(
      'group' => CSS_THEME,
      'preprocess' => FALSE
    ));
}

```
> 0 votes

---
Tags: theming
---


# Question
Title: User Revisioning and Workbench moderation modules only on certain content type
Is it possible to limit the revisioning and Workbench Moderation modules only on certain content types? On my site there are different content types that can be created but i need the features of these 2 modules to be used only on 1 of these types. Is there some way to do this?

# Answer
You can most definitely configure only one content type to use revisoning and content moderation.

For example, once the Workbench Moderation module is enabled, the Basic Page content type can be configured here: admin/structure/types/manage/page

Click the "Publishing Options" vertical tab, and you will see you have the option to check the "create new revision" checkbox, which will enable content revisioning.

Below that you can click the "Enable moderation of revisions" checkbox to engage the workbench moderation module features.

You must enable revisioning to enable workbench moderation. See image below:

For each content type which you desire content revisioning and workbench moderation, follow this procedure.
> 3 votes

---
Tags: 7, workbench, nodes
---


title: Sort by substring in views?

text:
# Question
Title: Sort by substring in views?
I have a content type with a full person's name in the title, in the format "John Smith". I want to have a view that sorts this content by last name. I've looked at the views interface but I don't see a way to get a substring. (I understand that this won't work perfectly but for our data set, it will work well enough.)

Will I have to add a field of the last name to the content type? Or is there a way I can get views to sort by a substring?

# Answer
> 0 votes
Adding a new field for the last name will be the easiest way. Sorting by a substring would mean that you also have to cover the possibility of spaces in first names and/or last names.

---
Tags: views
---


# Question
Title: Change from email id when admin approved user account
I want to change FROM Email id, when admin approved an user account.

Currently it is using admin email id. I want to use different email and my admin email id will remain same

Any Suggestions

# Answer
I don't have enough reputation to comment, so I am expanding user1081275's answer -

The message id for the confirmation message you want to alter is 'status\_activated'.

You can intercept outgoing mail with hook\_mail\_alter() in a custom module as described at https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook\_mail\_alter/7

```
function mycustommodule_mail_alter(&$message) {
  if ($message['id'] == 'status_activated') {
    $message['from'] = "mail@whatever.com";
  }
}

```

Per user.module, the ids for other messages defined by the User module in \_user\_mail\_notify() are:

```
 *   - 'register_admin_created': Welcome message for user created by the admin.
 *   - 'register_no_approval_required': Welcome message when user
 *     self-registers.
 *   - 'register_pending_approval': Welcome message, user pending admin
 *     approval.
 *   - 'password_reset': Password recovery request.
 *   - 'status_activated': Account activated.
 *   - 'status_blocked': Account blocked.
 *   - 'cancel_confirm': Account cancellation request.
 *   - 'status_canceled': Account canceled.

```
> 2 votes

# Answer
You can intercept outgoing mail with hook\_mail\_alter() as described here

https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook\_mail\_alter/7

such as :

```
<?php

  function mycustommodule_mail_alter(&$message) {
    $message['from'] = "mail@whatever.com";
  }

?>

```

NOTE : this changes it for all out going mail, you need to create a condition based on `$message['id']`

Also, as you really don't want that kind of thing hardcoded as it may change, you should create an admin settings form and save it to the database, returning the variable in the hook\_mail\_alter().
> 0 votes

# Answer
Try the settings at "site information", admin/config/system/site-information.
> -2 votes

---
Tags: 7, theming, rules
---


title: Workbench email

text:
# Question
Title: Workbench email
I have workbench Moderation module installed for moderating the content through three states and also using workbench email to send emails when there is any state changes.

In workbench Email There is option of sending email to Node Author when Node changed from Needs Review -\> Published.

But other person (not Author) can edit the content and push it to Needs Review, Is there any way that Person will get email about Node Publishing.

Thanks

# Answer
You can solve this by using the Rules module -- https://www.drupal.org/project/rules

Add a new rule: admin/config/workflow/rules/reaction/add

Enter a title and optionally, a tag

Select "After moderation transition" in the Node category for the "React on event" field

Click Save

Add a condition

for the "Select the condition to add" field, select "Content's current moderation state" in the node category

Leave the default "node" for the "Data Selector" field in the Content fieldset

Select "Needs Review" for the Value field in the Workbench Moderation State fieldset

Click Save

Add an action

For the "Select the action to add" field select "Send an email" in the System category

Next page, the TO fieldset

Click the "switch to data selection" button

Enter "node:author:mail" into the Data Selector field

Enter values in the Value field for the Subject, Message, and optionally the From and Language fieldsets

Click save.

You'll have a rule that sends an email to the author every time a node transitions to the Needs Review moderation state.
> 2 votes

---
Tags: 7, workbench
---


# Question
Title: Why does "Cancel People Account" not work?
I have Drupal 7 with Devel installed running over PHP internal server and MySQL. All user operations work correctly except Admin\>People\>Cancel Account operation.

This leads to the overlay **Add User** and a **Cancel Accounts** button. If I select the option: **Delete the account and its content** and press **Cancel Accounts**.

This leaves the overlay(displays the home page of the user)

All I want at this point is to be in the backend Overlay and show the message **Changes saved** or something similar. When I return to **Admin People overlay**, the user is still there.

Has anyone experienced a similar problem - and do you have a solution?

Thank You. -Robert.

# Answer
I can confirm your suggestion what it actually should be like and that actually exactly that should happen what you expect. After canceling an account you will be provided with further steps about the users written content etc. and finally you will become a progress bar showing the deletion or re-assigning of the written content of this user and the final confirmation about the success of it all.

The misbehaviour what you describe can be caused by several issues I only can list here for your research:

* there is a mod\_rewrite issue sometimes if the server is not set up correctly but this would actually also come up by many other tasks
* is your admin account clean and has never been modified? The user 0 is something special in Drupal world and can sometimes be corrupted by some changes on it
* you mentioned a local installation. Does has your DB user which is connected to the DB management of your Drupal installation, the right to DELETE in the mysql database?
* and as mentioned by Molot also the redirecting via overlay or any other modal frameworks and jquery can be the issue, often fixed by using jquery\_update module and playing around with jquery versions in the settings of the module.
* Also, any PHP cache or similar can cause freezing batch processes or overwrite the use of pecl progressbar (default in Drupal)
* Did you tried different users or only one? Or is this user you try to delete a spam account? They also can cause issues since they are not really registered but somehow signed up. This would be another story ...

Sorry, just some ideas...
> 0 votes

---
Tags: users, modal-dialogs
---


# Question
Title: How do I Pass a Nid to a webform and create a token for a different field on that node?
**Use Case**: I have a content type called "Team" which contains an email address. I have a view that creates a link to create a webform to contact the Team member and prepopulate the email address in a hidden field.

The Team member does not have a user profile. I do not want to pass the email to the webform url since that would expose it. I do understand how to pass a value to a webform. I want to avoid maintaining a custom module.

**Issue**: I hoped I could pass the Nid of the content entity and use an entity token to "lookup" the email as a default, hidden field and use that to generate the webform. I'm sure I'm missing something fundamental (please don't down the question ...)

**Question**: If I can get a token such as \[current-page:query:nid\] from the URL, how do I use that to get the email field \[node:field-email\] for say Nid=5? Should token chaining something like \[current-page:query:nid:field-email\] work? I can't seem to find good documentation on token reference chaining - that would be very helpful.

Installed D7.33, Token, Entity Token, Entity Reference.

I have viewed several similar cases that do not apply: https://drupal.stackexchange.com/questions/95774/how-to-pass-a-token-to-webform-from-a-node-relationship referencing/linking to an entityform and passing nid/other field information through the URL Creating a token for the image field file path with node reference nid https://drupal.stackexchange.com/questions/95774/how-to-pass-a-token-to-webform-from-a-node-relationship

**Note**: I found this module, but not sure if it is necessary: https://www.drupal.org/project/aet

# Answer
> 1 votes
How many teams are there?

If not too many, you could set up categories in your site contact form in `admin/structure/contact` that represent each team then pass the team name to the contact form, thus not exposing the email address.

---
Tags: webforms, entities, tokens
---


# Question
Title: Removing cached reference to missing table: services_user?
When trying to update user profiles via the Services module (not via drupal) - calling mysite.com/drupalgap/user/1.json as a POST with correct parameters - I'm getting the following error:

> 500 Internal Server Error : An error occurred (42S02): SQLSTATE\[42S02\]: Base table or view not found: 1146 Table 'mydbname.services\_user' doesn't exist

I've cleared all my caches but the problem persists. In fact, the `cache` table rebuilds itself with the a serialized reference to a `services_user` table in `schema` row. The line is huge, but here's the part with that reference:

```
s:13:"services_user";a:3:{s:6:"fields";a:3:{s:3:"uid";a:3:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;}s:7:"created";a:3:{s:4:"type";s:3:"int";s:8:"not null";b:1;s:7:"default";i:0;}s:7:"changed";a:3:{s:4:"type";s:3:"int";s:8:"not null";b:1;s:7:"default";i:0;}}s:6:"module";s:8:"services";s:4:"name";s:13:"services_user";}s:8:"smart_ip";a:5:{s:6:"fields";a:8:{s:8:"geoip_id";a:3:{s:4:"type";s:3:"int";s:4:"size";s:3:"big";s:8:"not null";b:1;}s:6:"ip_ref";a:3:{s:4:"type";s:3:"int";s:4:"size";s:3:"big";s:8:"not null";b:1;}s:12:"country_code";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:3;s:8:"not null";b:1;}s:6:"region";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:3;s:8:"not null";b:0;}s:4:"city";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:128;s:8:"not null";b:0;}s:3:"zip";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:8;s:8:"not null";b:0;}s:8:"latitude";a:3:{s:4:"type";s:5:"float";s:4:"size";s:3:"big";s:8:"not null";b:1;}s:9:"longitude";a:3:{s:4:"type";s:5:"float";s:4:"size";s:3:"big";s:8:"not null";b:1;}}

```

I currently have two Services configured. One is drupalgap and the other is my own custom for specialized queries and API needs. I've tried enabling / disabling a variety of resources in both my Service endpoints. Both have session authentication enabled, use a REST server, return json formats, and include a variety of resources including all of those user `system`, `drupalgap_user`, and `user`.

What should i do about this missing 'services\_user' table?

# Answer
That table was added in Services 7.x-3.10; it sounds like one of three things has happened:

1. You've updated the module but not run the database updates. If you have drush run `drush updb`, or visit /update.php to go through the process.
2. You've already run the updates but something went wrong
3. The table was removed accidentally (maybe by a backup restore)

In either of the last two cases, you can install the table manually with:

```
$schema = drupal_get_schema_unprocessed('services');
db_create_table('services_user', $schema['services_user']);

```

or

```
module_load_include('install', 'services');
services_update_7402();

```
> 0 votes

---
Tags: 7, users, caching, services, javascript
---


title: Display images with specific links

text:
# Question
Title: Display images with specific links
I created a *Banner* content type, which has an image and a Link fields. I allowed the upload of multiple images and adding multiple links in this content type.

I am using the Image Link Formatter module, which adds a formatter to display an image with a link. This works fine when I add a Banner node and preview it. I want this banner to be displayed by the Views Slideshow module.

Unfortunately, it doesn't work in a view block. When I choose to display the content, it renders all the banner images in a single slide (as might be expected). When I select the banner image field only, and choose the Image Link formatter, it displays the banner images, but not the links.

I tried hiding the link field, but this has no effect.

As an alternative solution, I tried following HOW TO INSTALL & SETUP VIEWS SLIDESHOW MODULE ON DRUPAL7? which suggests to use the *Output this field as a link* option for the image (which I did) and set it to the link field. This doesn't work as expected: The mapping multiplied the amount of banners, and output each banner once for eachlink.

How should I accomplish what I am trying to achieve?

# Answer
As pointed out by the comments posted under the question, the problem is that there are multiple images on a single node. To avoid problems like this, there should be one node per slide.
> 0 votes

---
Tags: 7, views, media
---


# Question
Title: How do I remove the "My account" and "Logout" links?
I am trying to sub-theme the Bootstrap theme. How do I remove the *My account* and *Logout* links from the navigation bar?

# Answer
> 3 votes
Try going to Appearance settings on your sub-theme `admin/appearance/settings/...` and uncheck Secondary menu.

If that doesn't work, check menu settings at `admin/structure/menu/settings` and make sure you haven't defaulted the main menu to "User menu".

# Answer
> 1 votes
Go to: admin/structure/block find user menu and set 'none', as region.

# Answer
> 1 votes
Simply, navigate to the user menu (admin/structure/menu/manage/user-menu) and deselect "enabled" for each item.

---
Tags: 7, theming
---


# Question
Title: Creating a thumbnail Navigation for a Flexslider
I want to create this:

http://flexslider.woothemes.com/thumbnail-controlnav.html

Using Flexslider.

In Flexslider's Advanced Options I see there is an option to "Use as Navigation". I've tried setting another Flexslider slidehow (full of thumbnails) as the navigation but it doesn't seem to work right.

I just need to have a main slider and a slider under it full of thumbnails that acts as a navigation menu for the main slider. How can I do this?

# Answer
> 1 votes
* Install Flexslider module
* If you need to display images as a view, select "slider w/thumbnail controlnav pattern" option set in Flexslider display mode settings.
* If you displays images a multi-valued image field, select "slider w/thumbnail controlnav pattern" for the field in Manage display tab.

Please note that controlNav pattern (you mentioned) is not the same as thumbnail slider.

---
Tags: views, javascript
---


# Question
Title: Dynamic dependent field with entity reference and organic groups
I created a node type "friendly match". In this node type I got a field "club" that is an entity reference/ og reference to the "club" organic groups of the current user.

The second field named "team" should display all "team" organic groups of the club selected in the first field.

Another user gave me a hint for this module https://www.drupal.org/project/ddf

This module should allow to pass an argument from the club field to the team field. The team has use mode "views: filter by an entity reference view with dynamic arguments".

It seems that I also have to define some contextual filter in the view but I just can't figure out what filter I need to apply.

A user posted a example of the way to use the module https://www.drupal.org/node/2095179#comment-8425253

Problem is I cant adapt it to my needs. The second field always show all teams the user belongs to not just the teams of the selected club.

It would be a great help if someone could give me a hint to proceed.

Thank you all.

# Answer
> 0 votes
If I understand it correctly, you want to implement something like this

```
Field "Club"    Field "Team"
Club A          Team A1
                Team A2
Club B          Team B1
                Team B2

```

So i think you have to create a **club entity reference field** in **team OG** group content type. Then create the entity reference view collecting the content type: "team OG" type, contextual filter club field, and relationship referenced entity.

i'll update my answer as soon i document the steps well :-)

---
Tags: views, organic-groups
---


# Question
Title: How to customize profile2 module profile edit form using template method?
How to customize the profile edit form of the Profile2 module using a template?

Profile2 has the main profile (`admin/structure/profiles/manage/main`), and it is set to provide a separate page for editing profiles (`profile-main/1/edit`).

In Drupal 7, for a content type such as *faq*, I can use a template to customized its edit form.

In `template.php`, I am using the following code:

```
function MYTHEME_theme(&$existing, $type, $theme, $path) {
  return array(
      'faq_node_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'node--faq--edit',
      'render element' => 'form',
  ),
  );
}

```

I then create `node--faq--edit.tpl.php`, where I can customize it.

What is the equivalent method I could use for a Profile2 profile edit form?

# Answer
You should use `form_id` as theme key in `hook_theme()`, which is `user_profile_form` in the case.

```
function MYTHEME_theme(&$existing, $type, $theme, $path) {
  return array(
    'user_profile_form' => array(
      // …
    ),
  );
}

```

See Theme Profile2 Form, a support request opened for the Profile2 module.
> 0 votes

---
Tags: 7, theming
---


# Question
Title: How to check spelling of user typed text in a form textbox
I built a form which have a text field for take input from user.

Now I want to implement a spell check module or something which can check spell when user type some word or sentence in the text field. I Googled a lot but didn't find any result for my search. Find spell checker for WYSIWYG editor but not for my search.

How can I implement spell checker for text field in a form.

# Answer
You can use *HTML spellcheck Attribute* for the textfield. The spellcheck attribute is new in HTML5.

> The spellcheck attribute specifies whether the element is to have its spelling and grammar checked or not.

You can use this attribute in your textfield like follows. I've tested this and working fine.

```
  $form['check'] = array(
        '#type' => 'textfield',
        "#attributes" => array("spellcheck" => "true")
      );

```
> 11 votes

# Answer
There is nothing ready made solution available to this you need to make your custom module for the same I can give you some information about how can you achieve this:

you can start with module Spell Checker it is for drupal 6 so for D7 you need to enhance the same, it uses jQuery spell-checker plugin and integrated that as Drupal module.

also there is a paid service available if you are interested http://www.phpspellcheck.com/
> 0 votes

---
Tags: forms, 7
---


title: Files permissions with organic groups

text:
# Question
Title: Files permissions with organic groups
Is there a way to use organic groups to manage file permissions for files uploaded to site? I would like have of at the node level and file level.

# Answer
> 0 votes
The submodule 'Organic groups field access' of the OG project should be able to help you manage file access based on Organic Group permissions.

You can create private Organic Groups by enabling the OG submodule 'Organic groups access control'.

Depending on the useless: Make sure to add a 'Group visibility' field to the Group bundle or a Group Content visibility to the group content bundle at admin/config/group/fields.

---
Tags: organic-groups
---


# Question
Title: Token filter does not show image field with FlexSlider formatter
I want to display a gallery with the FlexSlider formatter in a Body field.

I installed the Token and Token filter modules and enabled "token filter" in text formats (admin/config/content/formats).

On my content type (admin/structure/types/manage/\[content\_type\]/display) I enabled the "Token" display mode in "Extended display parameters".

For the Token display mode (admin/structure/types/manage/\[content\_type\]/display/token) I set the FlexSlider formatter for my image field (field\_gallery).

I added a node with the \[node:field\_gallery\] token in the Body field but the token is being replaced with nothing.

How can I make an image field using the flex slider field formatter work with the token filter module?

# Answer
My solution.

Install custom\_formatters module.

Create a view with FlexSlider formatter:

```
    $view = new view();
    $view->name = 'field_slider';
    $view->description = '';
    $view->tag = 'default';
    $view->base_table = 'node';
    $view->human_name = 'Slider';
    $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['use_more_always'] = FALSE;
    $handler->display->display_options['use_more_text'] = 'more';
    $handler->display->display_options['access']['type'] = 'perm';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['exposed_form']['options']['submit_button'] = 'Apply';
    $handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Reset';
    $handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sort by';
    $handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Asc';
    $handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Desc';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Elements';
    $handler->display->display_options['pager']['options']['expose']['items_per_page_options_all_label'] = '- All -';
    $handler->display->display_options['pager']['options']['expose']['offset_label'] = 'Skip';
    $handler->display->display_options['pager']['options']['tags']['first'] = '« first';
    $handler->display->display_options['pager']['options']['tags']['previous'] = '‹ prev';
    $handler->display->display_options['pager']['options']['tags']['next'] = 'next›';
    $handler->display->display_options['pager']['options']['tags']['last'] = 'last»';
    $handler->display->display_options['style_plugin'] = 'flexslider';
    $handler->display->display_options['style_options']['optionset'] = 'gallery_in_text';
    $handler->display->display_options['row_plugin'] = 'fields';
    /*  */
    $handler->display->display_options['fields']['field_gal']['id'] = 'field_gal';
    $handler->display->display_options['fields']['field_gal']['table'] = 'field_data_field_gal';
    $handler->display->display_options['fields']['field_gal']['field'] = 'field_gal';
    $handler->display->display_options['fields']['field_gal']['label'] = '';
    $handler->display->display_options['fields']['field_gal']['element_label_colon'] = FALSE;
    $handler->display->display_options['fields']['field_gal']['click_sort_column'] = 'fid';
    $handler->display->display_options['fields']['field_gal']['settings'] = array(
      'image_style' => '',
      'image_link' => '',
    );
    $handler->display->display_options['fields']['field_gal']['group_rows'] = FALSE;
    $handler->display->display_options['fields']['field_gal']['delta_offset'] = '0';
    /*  */
    $handler->display->display_options['sorts']['created']['id'] = 'created';
    $handler->display->display_options['sorts']['created']['table'] = 'node';
    $handler->display->display_options['sorts']['created']['field'] = 'created';
    $handler->display->display_options['sorts']['created']['order'] = 'DESC';
    /*  */
    $handler->display->display_options['arguments']['nid']['id'] = 'nid';
    $handler->display->display_options['arguments']['nid']['table'] = 'node';
    $handler->display->display_options['arguments']['nid']['field'] = 'nid';
    $handler->display->display_options['arguments']['nid']['default_action'] = 'not found';
    $handler->display->display_options['arguments']['nid']['exception']['title'] = 'All';
    $handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
    $handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
    $handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
    /*  */
    $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;
    /*  */
    $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(
      'page' => 'page',
    );

```

Go to the custom formatters settings, create new formatter for Image field: Format: PHP Field types: Image Formetter (php):

```
  print views_embed_view('field_slider','default', $variables['#object']->nid);

```

Or import this:

```
    $formatter = new stdClass();
    $formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
    $formatter->api_version = 2;
    $formatter->name = 'gallery_views';
    $formatter->label = 'Gallery views';
    $formatter->description = '';
    $formatter->mode = 'php';
    $formatter->field_types = 'image';
    $formatter->code = 'print views_embed_view(\'field_slider\',\'default\', $variables[\'#object\']->nid);';
    $formatter->fapi = '';

```

Then go to the Token tab (admin/structure/types/manage/\[your\_content\_type\]/display/token), set the Gallery views formatter. Now it works.
> 1 votes

---
Tags: 7, javascript, tokens
---


title: Adding a subtitle to the main title

text:
# Question
Title: Adding a subtitle to the main title
My Website name is Subham Soni.

I want to add two more lines below it.

One as "Developer" and then in another line a quote along with the author.

How do I do it?

# Answer
> 0 votes
As @Smalution pointed out, this is generally done using the site Slogan option which is set at `/admin/config/system/site-information`.

This is the standard way of doing this but relies on the theme you are using have the line

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

```

Some where in the page.tpl.php

If you are creating your own theme, or hacking some one elses make sure this is in there. But, in some themes (this goes for Garland that ships with D7) you will see something like

```
<?php print $site_name_and_slogan ?>

```

in the page.tpl.

This is because the page template has gone through a preprocess function in the template.php i.e `function garland_preprocess_page(&$vars)` and the slogan has been wrapped with the title and a new variable created :

```
$vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text;

```

So if you can't see `$site_slogan` straight away that's probably why.

---
Tags: 7, blocks
---


title: Taxonomy Hierarchy URL

text:
# Question
Title: Taxonomy Hierarchy URL
I have a taxonomy vocabulary with name "Animals" along with following terms

* Mammals
+ Animalia
+ Chordata
+ Mammalia
- Bat
- Bear
- Fox

I have created a view with contextual filters in which I need to show the hierarchy of the taxonomy terms For example : URL : base\_URL/Mammals/Mammalia/Bat

Taxonomy Implementation that I have made :

* Added relationship of taxonomy terms on node
* Added relationship of parent term
* Added contextual filters for parent term.
* Added contextual filters for taxonomy term id with depth. (Please find the settings of the same in attached screenshot).

But actual results I'm getting is "base\_URL/tid" but expected URL result what I need is "base\_URL/Mammals/Mammalia/Bat".

Can anyone please help me out with detailed implementation?

# Answer
I can't see any screenshot.

It seems that your problem is with url and if it is then go for Path Auto module.

The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias.
> 0 votes

---
Tags: taxonomy-terms
---


# Question
Title: How to scrape content from a Drupal Site?
I am a victim of Drupageddon on one of my sites and even though I patched Drupal core (maybe not fast enough) recently my Drupal database got completely messed up and my webhoster confirmed there were massive attacks on the Drupal database.

Now, I have the luck that my site still is visible including all content. But I cant login anymore, getting PDOexceptions and so on.

My question is, how to backup the content (nodes) from remote, maybe scraping node by node, field by field? (Reverting to backups before Oct/15 is no option currently, I need all the content.)

---

**Update**: The database is a mess, I can not login because of database errors. I need a remote solution. Or maybe I can extract the content from a database dump?

# Answer
The way I would go about it is:

1. At .htaccess / nginx.conf level, I'd disable access to site for anyone but my own IP. You know, to be sure.
2. Directly in database, change email address of user 1 to my own OR restore user table from a backup
3. Use password restore feature to get admin access
4. Use whatever module I want to export content (stripping it from any html, js, php if it's there)
5. Delete site thoroughly from the server
6. Rebuild it, or restore it from pre-Drupageddon backup
7. Re-import content.
> 1 votes

---
Tags: files, nodes, backups
---


# Question
Title: Javascript link in theme.info not working Drupal 7
Why is my jquery.js file not found when I use this code in my theme.info?

Im using drupal 7.

```
scripts[] = js/jquery.js

```

I got this code from the drupal page and I'm 100% sure its the right path. what did i do wrong here?

Thanks for helping!

# Answer
> 1 votes
Clear your cache. I think it may work for you.

---
Tags: 7, javascript, uri
---


# Question
Title: Views custom field select list like views custom field
I'm looking for a module which can allow to add a select list like views customfield provides a text field. The select list are on the based of above fields. Example : I have Edit and delete operations in each views row corresponding to the result.I need these operations in select list. Any module suggestions ?

P.S. : Please don't suggest about views\_php.I can write custom handlers instead of this module.

# Answer
This is very easy to achieve but does not do much on it's own :

* Create a new field for something like Content:NID
* Go to Theme Information in the view settings
* Find the template fie name suggested for your field
* Create that file in your theme folder eg `views-view-field--my-view--page--title.tpl.php`
* Press rescan templates in theme information (file name will go bold)
* Add the following to the file

```
<select name="ops_<?php print $row->nid; ?>">
  <option value="edit">edit</option>
  <option value="delete">delete</option>
</select>

```

It doesn't do anything on it's own, you could wrap it in a `<form>` and specify a path as your method to process it, or use jQuery to do something.

But ... There is also an excellent module called View Bulk Operations (VBO) which will probably give you all the functionality you need.
> 0 votes

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


# Question
Title: Ctools content type- How do I access a context that is provided by a panel page?
I'm trying to add a ctools custom content type to the *user profile* override provided by panels.

I have added a context, *Logged-in user*. I can access the values of this variable in my custom content type like this:

```
dpm($context['context_user_1']);

```

However, I also want to access the values for *user-being-viewed*, which is available in the *user profile* page by default. With the devel module, I can see the variables are in `$context` under `argument_entity_id:user1`, but I can't access them like this:

```
dpm($context['argument_entity_id:user1']);

```

How can I access the variables of a context provided by default in Panels?

# Answer
> 0 votes
There might be a more elegant way, but here's what I came up with:

```
$user = reset($context);
$user = $user->data;

```

---
Tags: panels, chaos-tool-suite
---


# Question
Title: How to display rss from external site into a view and sort them?
I want to import RSS from an external website and then display them in a view content pane. I also have to sort them by date. The External RSS contains Title, Body and Date but the Date is hidden by default in RSS, I guess. I checked the Aggregator and feeds module but I don't think it serves the purpose because i also have to link the title to the Nodes on the External site. Thank you.

# Answer
If feeds are read by drupal core aggregator module then you can do this with the help of views module itself.

Rough Example: Settings as per the screenshots

1. Create new view
2. Add fields to your view.

This will show feeds in view and you can easily do whatever you want to do with it. Hopes this will help.
> 2 votes

---
Tags: views, 7, feeds
---


# Question
Title: Key / Value fields module where you can choose the type?
Is there a module which creates a field where you can choose the field type of the key and also the value during content type creation?

# Answer
> 1 votes
You can use the Field Collection module to achieve that functionality:

> Provides a field-collection field, to which any number of fields can be attached.
>
> A field collection is internally represented as an entity, which is embedded in the host entity. Thus, if desired field collections may be viewed and edited separately too.

The idea is:

1. Create a Field Collection.
2. Add key/value fields to it with the field types of your choice.
3. Add a Field Collection field to the content type you want these key/value fields on.
4. Set the source of that Field Collection field to the new Field Collection you've just created.
5. Repeat for whatever other content types you need to.

---
Tags: 7, entities
---


# Question
Title: Drupal 7 Views table style with exposed filters
I want to place my exposed views filters in a tabular format, something like below

How to achieve this?

# Answer
The only way to do this is in the theme layer.

One way would be to implement a theme override - probably with a hook\_preprocess function, maybe also hook\_form\_alter. Embedding the form in a table will be particularly tricky, since the exposed filter and results table are rendered in distinct processes.

If you are comfortable with jQuery, it might be easier to do this with javascript.
> 1 votes

# Answer
I too faced a similar problem. As I understand it Theming exposed filters and tables are at different levels. The exposed filter is disclosed in views-view.tpl.php, it is the same conclusion as the content , I think that this variable has generated a table or row. The output is in the same table views-view-table.tpl.php. I do not have enough practice at it, but I think that it is necessary to develop a plug-in for vieschs and it override the views-view.tpl.php where instead of Display a table and has already exposed within this place filters. I do not know if that is right?

P.S. this text translated by google translator.
> 1 votes

# Answer
The module that you are looking for is Views Table Filter.

The module page reads

> This module allows to move views exposed filters in table header if view display is table. The configuration for this option is in Better Exposed Filters configuration form, so the module depends on BEF.
> 0 votes

---
Tags: 7, views
---