title: Oauth social login services not working

text:
# Question
Title: Oauth social login services not working
Can any body help me out how do I accomplish social networking login using login using loginprovider.

I have done this for website using oauth connector.

I tried lot but no success for mobile services. What should I pass in parameters, end point I got is something like http://www.example.com/oauthlogin/api/login/info.json. Any body having idea how legged process is done through oauth 3.x and services 3.x. Or any other options available?

# Answer
> 0 votes
I use HybridAuth Social Login for login system via social networks

---
Tags: services, authentication-authorization
---


# Question
Title: How to get fields of certain content type in template file without writing iteration loops in tpls?
Here I'm getting all fields of certain content type in my `.tpl.php` file with the help of **hook\_theme**.

```
return theme('carousal', array('carousal' => $fields));

```

**And my template file is something like this:**

```
<?php
global $fields;
foreach($fields as $key => $value){
echo $value['title'];
print render ($value['fields']['body']);
}
?>

```

Now, what I want is, **I don't wanna use foreach loop in my template file**. And if possible, not even any php tags.

How far **is it possible to render fields in template file without using any loop?**

**Can't we write only "BODY" and we get "body" field rendered itself automatically?**

I don't know whether it's possible or not. If it's possible, kindly let me know the way out of this.

# Answer
You can pass your $fields to a custom function. Run your logic or foreach loop in the custom function and pass the title,body values back. Thus you would not need to use the foreach loop in template file.

Here is some sample code if it helps.

```
$field_data = _my_function($fields);
$data = theme('carousal', array('carousal' => $field_data));
return $data;

```
> 0 votes

# Answer
Try this

```
print render($content['your_field_name']);

```

this will print that field value .
> -1 votes

---
Tags: theming
---


# Question
Title: How to redirect by adding something after pathauto url?
I am trying to do a simple thing. Whenever an anonymous user views a content , I want to redirect the user to

`node's-url/#overlay=signup`

So, how do I modify the URL to use #overlay=signup at the end for anon users?

I tried to do so by implementing rules.
Event: Content is viewed
Condition: User role is anonymous
Action: Redirect url.

I don't know how to add the `pathauto-url/#overlay=signup`.

# Answer
> 1 votes
What's what Splash module does. See Thickbox option. More about the module:

> Display any internal path, external URL or text as a splash page before going to the actual frontpage.

# Answer
> 1 votes
You should be able to use your existing rule (see below), but in the Action for redirect URL put `[site:current-page:path]/#overlay=signup` or `[node:url]/#overlay=signup` if the former doesn't work.

*Existing rule (just for reference)* \-

**Event:** Content is viewed

**Condition:** User role is anonymous

**Action:** Redirect url.

# Answer
> 1 votes
You can use the module splashify You can determine how often the splash page should show up in the configuration areas (always, daily, weekly, monthly).I think its good for you and for altering your url you can use the theme\_links, read the documentation. Best of luck.

```
<?php
  // $node = a given node object.
  // $term = a specific term object.
  $links[] = array(
    'href'  => 'node/' . $node->nid,
    'title' => $term->name,
    'query' => array('tag' => $term->tid),
  );
  // This will end up as e.g.:
  // <li><a href="node/123?tag=456">termname</a></li>
?>

```

above is the reference code wrap with anonymous user condition on node pre process function.

# Answer
> 0 votes
At least the event you're using for your rule needs to be corrected. Because what "Content is viewed" actually means, seems to be like so:

* The event ***Content is viewed*** is what it is: the user has (already) started viewing the content.
* The (system) event ***Drupal is initializing*** is what you should use instead (possible combined with other Events and/or Actions), if you want to trigger some Rules "Action(s)" **BEFORE** the user can start viewing (= looking at) the content.

For more details, and a working sample (in Rules 'export format'), refer to How to specify a Rules event like "Content is 'going to be' viewed"?

**Be aware**: this applies to D7 ... and D6 is another story (from the question context I'm not sure if this is for D6 or D7 ...).

---
Tags: rules, path-aliases, redirection
---


title: History of particular content items

text:
# Question
Title: History of particular content items
I want to track the history of particular content items on particular date, ex: i have saved the node of content on 9/4/2015 and also i have edited the same node on 9/9/15, so when i give the from date 9/4/15 to date 9/9/15 with filter condition field,it should show the all changes that has been done for that particular filter condition field on **From to To date mentioned**, I tried to create a view of content revisions but it's of no use because revisions are shown for all content items. How do I create a view of the revisions of a specific item?by giving filter condition From to To date.

# Answer
You can try the Workbench Moderation module.

> Workbench Moderation adds arbitrary moderation states to Drupal core's "unpublished" and "published" node states, and affects the behavior of node revisions when nodes are published. Moderation states are tracked per-revision; rather than moderating nodes, Workbench Moderation moderates revisions.
> 1 votes

# Answer
Not 100% certain I understand the question, but generally all you need to do to set up revision history is goto the edit screen for the content type, open the "Publishing options" tab at the bottom and check the "Create new revision" checkbox.

Note that you won't see any change to the UI until you save the node for the second time as that is when the first revertible revision is created. At that moment the "Revisions" tab will appear above the content.
> 1 votes

---
Tags: views, nodes
---


title: Custom rules component execution

text:
# Question
Title: Custom rules component execution
I have created rules component with some custom fields fc\_home\_city,fc\_pin, fc\_loan. When I am trying to execute then asking to fill text box value of fc\_home, fc\_pin and fc\_loan manually I have attached screen shot below. I want to pass all the variables value from my database and calculate user points according to what he had fill in my custom registration form . How I will do it with custom code? Is any idea?

Ex:

In screen attached below after rules execution asking HOME CITY value but I want to pass Home city value from our end with custom code.

Thanks

Thanks

# Answer
> 0 votes
When you say "what he had fill in my custom registration form" do you mean that fc\_home\_city, fc\_pin and fc\_loan have equivalent fields on the user entity (probably called something like field\_fc\_home\_city, etc)?

If so then I don't see why you are trying to populate those fields with code. One of the main advantages of the Rules framework is that you can can use the token selector system to pass in values nested into the objects you have to hand without having to write a line of code.

For example if you wanted to pass in the field\_fc\_home\_city value of the current logged in user to the "Home city" field then you'd enter "`account:field-fc-home-city`" into that field and then every time it executes, that token will be replaced with the correct value for the current logged in user.

If it's not the logged in user you want to work with then so long as the component receives the user account as a parameter then you will be able to use the system to get the values from that user entity.

The javascript drilldown mechanism on the fields should help you get to the right token, otherwise you can press "Switch to direct input mode" and find the token in the "Replacement patterns" fieldset.

A good overview of how it works can be found here.

---
Tags: rules
---


# Question
Title: How to iterate extra fields in a webform component
When I select the extra field of a webform component:

```
$webform_components = db_select('webform_component', 'c')
                          ->fields('c', array('type', 'form_key', 'extra'))
                          ->condition('nid', $nid)
                          ->execute()
                          ->fetchAll();

```

The extra field is something like this (the following example is a grid component):

```
"a:8:{s:13:\"title_display\";s:4:\"none\";s:7:\"private\";i:0;s:15:\"wrapper_classes\";s:0:\"\";s:6:\"sticky\";i:1;s:7:\"options\";s:20:\"5|poor\n10|excellent\n\";s:18:\"custom_option_keys\";i:1;s:9:\"questions\";s:159:\"mensaje|Each message is associated with a language, which may or may not be the\nactual|current user's selected language, depending on the type of e-mail being\n\";s:20:\"custom_question_keys\";i:1;}"

```

I want to get the options and the questions. In the previous example:

```
\"options\";s:20:\"5|poor\n10|excellent\

```

**Option 1**: 5 (key) | poor (value)

**Option 2**: 10 (key) | excellent (value)

```
\"questions\";s:159:\"mensaje|Each message is associated with a language, which may or may not be the\nactual|current user's selected language, depending on the type of e-mail being

```

**Question 1**: mensaje (key) | Each message \[...\] (value)

**Question 2**: actual (key)| current user's \[...\] (value)

I don't know how to process this *extra* string. I tried to transform it to an array and a json, but it didn't work.

Thank you for your help! :)

# Answer
It's a serialised PHP string, so:

```
$unserialised = unserialize($input);

// Split $unserialised['options'] by the '|' char, then extract keys/values

```
> 0 votes

---
Tags: 7, webforms
---


# Question
Title: How to get "Show block on specific pages" working?
I would like to show a certain block only on one specific page. I want to use the *Show block on specific pages* feature for it. I have tried to set the url of my page like `content/hills-restoration-process` as well as the actual node number, like `/node/36` but I don't seem to get it to work correctly. What am I doing wrong here? It seems like an easy and straight forward feature... Thanks for hints and suggestions!

# Answer
> 1 votes
When you use this field don't provide the leading slash. Try `node/36`.

Not sure why the alias wouldn't work - perhaps there's a character out of place. Node numbers work better because the block then doesn't disappear if the alias changes.

# Answer
> 0 votes
If this is a test site, first try making the block unrestricted.

If it does not appear, try assigning it to different content regions. If it appears in some but not others, this is probably a theming issue.

If it appears on every page as expected, you can then start applying your page restriction rule.

If this is a live site, follow the same approach but restrict the block to administrators until you have tracked down the problem.

---
Tags: 7, blocks
---


# Question
Title: Unique field value for all nodes and content types
I have list integer field in 3 content types and each have same possible values (from 1 to 6) and I need to disable user to choose the same number for two nodes, so each node with this field filled in need to be unique.

I found Unique field module but it is not working for me, because I have field in each content type and I need to look at all nodes from all content types and this module is on content type base.

Basic example of what I need:

Field **field\_1** from content type **type\_1** have value **5**, so **field\_2** from content type **type\_2** and **field\_3** from content type **type\_3** can't have value **5**.

Any idea how to achieve this?

# Answer
Check out this example

```
function custom_node_validate($node, $form) {
  if ($node->type == 'page') {
    //retrieve the value for your field using Entity API
    $wrapper = entity_metadata_wrapper('node', $node);
    $value = $wrapper->field_collection->field_unique->value();

    //Execute a count query to see if there's other similar values.
    $query = new EntityFieldQuery;
    $query->entityCondition('entity_type', 'field_collection_item')
      ->fieldCondition('field_unique', 'value', $value)
      ->count();
    $count = $query->execute();
    if ($count > 1) {
      form_set_error('field_unique', 'Unique field value is already used.');
    }
  }
}

```
> 1 votes

---
Tags: nodes
---


# Question
Title: How to insert the image field in the menu links
How to insert the image field in the menu links? I've added an image field in the vocabulary I've created and uploaded image on each terms. I am able to display those images and the other fields I require using the views and I've used the taxonomy\_menu to add the terms in the menu links, but one of my requirements is to display those image into the menu links. I don't think that the menu\_icons module is the solution, I don't want to double up the work in uploading the image. Please bear with my English and hoping that I explained it well. Thank you.

# Answer
> 0 votes
You can try using the module Menu Minipanels. This module will allow you to use views and custom blocks inside the menu.

Or you can customize the menu display as specified here.

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


# Question
Title: Hiding the field label when creating a content type
I have created a content type called "Design" in which there are 3 fields. When creating this content type I want to hide the label of fields. How would I do that?

# Answer
> 3 votes
Please go to admin/structure/types/manage/\[your-content-type\]/display

And you can hide labels accordingly.

---
Tags: entities, nodes
---


# Question
Title: How can I override a module's file via hook_menu_alter()?
I have the following code in my hook\_menu\_alter().

```
<?php

function bonus_menu_alter(&$items) {

  if (!empty($items['things'])){

    $items['things']['title'] = t("New title");
    $items['things']['callback'] = 'new_callback';
    $items['things']['file path'] = drupal_get_path("module", "bonus")."/includes/";
    $items['things']['file'] = 'bonus.pages.inc';

  }

}

```

The problem is that the file path of the new file is including the original modules path and spitting this out:

```
/var/www/staging/sites/all/modules/things/sites/all/modules/bonus/includes/bonus.pages.inc

```

The original implementation of the parent hook\_menu():

```
/**
 * Implements hook_menu().
 */
function things_menu() {
  $items['things'] = array(
    'title' => 'Things title',
    'page callback' => 'things_callback',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'file' => 'includes/things.pages.inc',
  );
  return $items;
}

```

What could I be doing wrong?

# Answer
> 8 votes
I think this happens because your alter hook does not update the value for `$items['bonus']['module']`, which was automatically set to 'things' when menu\_router\_build processed `things_menu()`. Try this:

```
$items['bonus']['module'] = 'bonus';
$items['bonus']['file path'] = '/includes/';
$items['bonus']['file'] = 'bonus.pages.inc';

```

or simply this, more like the things module does:

```
$items['bonus']['module'] = 'bonus';
$items['bonus']['file'] = 'includes/bonus.pages.inc';

```

---
Tags: routes
---


# Question
Title: Drupal 7 webform Version: 7.x-4.5 not sending email
After updating to Webform Version: 7.x-4.5 the email functionality is not working, which I assume it could be due to change in tokens.

I have a Webform as block a which is attached to product content type and want to send the contact form information which is webform to current node author.

I am using \[current-page:node:author:mail\] token as a hidden field in the webform, which used to work until I update to new version of webform and since then the worbfrom stop sending email to author email.

What I am doing:

In the webofrm I have a hidden field author\_mail where the default value is set to \[current-page:node:author:mail\]

At the Webform email setting I set E-mail to address to Component: Author Mail.

Any idea what token to use if not \[current-page:node:author:mail\]?

Is there any way to send the Webfrom content to current page author email?

Thanks for the help.

# Answer
> 1 votes
If you want to make token `[current-page:node:author:mail]` working, you need to apply this Token module patch.

Source.

---
Tags: 7, webforms, emails
---


# Question
Title: i want to hide comment in drupal 7 which is displayed like Submitted by Anonymous (not verified) on Sat, 09/05/2015 - 04:15
i want to hide comment in Drupal7 which is displayed like Submitted by Anonymous (not verified) on Sat, 09/05/2015 - 04:15

# Answer
> 1 votes
You can remove the **Author username** and **Publish Date** by editing the content type from

`Structure > content types > YOUR CONTENT TYPE`

---
Tags: comments
---


# Question
Title: How to completely wipe and rebuild drupal menus?
A while ago I found a cool blog post that detailed how to empty the menu tables, and rebuild the menu system with a drush php call, a necessity since the site will be unusable after emptying those mysql tables. This way, you could reset your menus like it was a new Drupal site.

Can anyone detail this technique or do you have the link for that blog?

# Answer
I have answered this question here How do I call the menu\_rebuild function in Drupal 7?

It worked for me just fine.
> 1 votes

# Answer
I have been looking a while for a solution to the problem to rebuild Drupal menus until I stumbled upon a Drupal issue that helped me. My solution (in a php script) is the following:

```
db_query("DELETE FROM {menu_links} WHERE module = 'system'");
db_query("DELETE FROM {menu_links} WHERE menu_name = 'management'");
menu_rebuild();

```

This could also be done by entering the queries through phpmyadmin or something alike:

```
DELETE FROM {menu_links} WHERE module = 'system'
DELETE FROM {menu_links} WHERE menu_name = 'management'

```

And then rebuilding the menu structure. If you use the devel module, you can achieve that by visiting the page `/devel/menu/reset`. I you don't have the devel module, I'm not sure how to rebuild the menu structure.

Don't forget to **backup your database** before you try this.
> 6 votes

# Answer
Maybe this is post: http://www.zyxware.com/articles/2454/how-to-rebuild-menu-links-table-and-rebuild-the-navigation-menu

```
DELETE FROM menu_links WHERE menu_name='navigation'

```

Then visit modules page, and the menu will be rebuilt.

I tested in Drupal 6.
> 2 votes

---
Tags: 7, routes, drush
---


# Question
Title: How to specify multiple submit handlers for multiple forms
I am implementing `hook_forms` in my custom module and I don't know how to have multiple form submit handlers.

Here is my custom form function:

```
function data_retrieval_main_form()
{
    $form ['field2'] = array(
        '#type' => 'textfield',
        '#title' => t('Name'),
        '#default_value' => $name,
        '#maxlength' => 127,
    );

    $form ['field3'] = array(
        '#type' => 'textfield',
        '#title' => t('Age'),
        '#default_value' => $age,
        '#maxlength' => 127,
    );

    $form['fileupload'] = array(
        '#title' => t('Choose Image'),
        '#type' => 'file',
    );

    $form ['submit_field'] = array(
        '#type' => 'submit',
        '#default_value' => 'Submit',
    );

    return $form;
}

```

Here I am implementing `hook_forms`:

```
 function hook_forms($form_id, $args) {

      $forms ['mymodule_first_form'] = array(
        'callback' => 'data_retrieval_main_form',
      );

      $forms ['mymodule_second_form'] = array(
        'callback' => 'mymodule_main_form',
        'callback arguments' => array('some parameter'),
      );

      return $forms;
    }

```

Now I previously had a single form using `hook_form` and the handler was simply like this:

```
function data_retrieval_form_submit($form_id, &$form_state)
{
// validation and submission of form
}

```

But now that I have multiple forms, how do I have multiple submit handlers for the forms, is there a way in Drupal that checks which form is being submitted?

# Answer
You can specify a submit handler for each of your forms. Examples:

Override default handler with custom handler (new array):

```
$form['#submit'] = array('data_retrieval_form_submit');

```

Run custom handler after default (append to array):

```
$form['#submit'][] = 'data_retrieval_form_submit';

```

Run custom handler before default (prepend array):

```
array_unshift($form['#submit'], 'data_retrieval_form_submit');

```

You can add it to the `$form` array in a custom form builder function, or alter an existing form via hook\_form\_alter.
> 2 votes

---
Tags: forms
---


# Question
Title: Ajax replaced elements not available in form submit callback
I have some elements in a form as below:

```
$form['provider'] = array(
    '#type' => 'select',
    '#title' => t('Provider'),
    '#required' => TRUE,
    '#options' => $some_options,
    '#ajax' => array(
        'callback' => 'my_callback_func',
         'wrapper' => 'tests-div',
         'method' => 'replace',
         'effect' => 'fade',
     ),
);

$form['tests'] = array(
    '#type' => 'select',
    '#title' => t('Tests'),
    '#required' => TRUE,
    '#prefix' => '<div id="tests-div">',
    '#suffix' => '</div>',
    '#options' => array(''),
    '#validated' => TRUE,
 );

```

When the `provider` select box value is changed, the callback `my_callback_func` checks the chosen value of the select box, and returns a modified version of `tests` select box with some new options set.

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

    [snipped code which reads form data and calculates $some_new_opts ]

    $form['tests'] = array(
          '#type' => 'select',
          '#title' => t('Tests'),
          '#required' => TRUE,
          '#prefix' => '<div id="tests-div">',
          '#suffix' => '</div>',
          '#options' => $some_new_opts,
          '#validated' => TRUE,
    );

    return $form['tests'];
}

```

So far so good - when I change the value of the `provider` select I can see the Ajax event firing, the new options appear in the `tests` checkbox and I can select from them. But then when I submit the form using

```
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'go for it',
    '#submit' => array('my_post_submit_function'),
 );

```

none of the Ajax supplied values are visible in either `form` or `form_state` within `my_post_submit_function`. Instead, the original value (the empty array) is always shown in `$form['tests']['#options']`, and `$form_state['values']['tests']` is null ("").

What am I doing wrong ?

**Updated 4th Sept**

I'm still trying to solve this problem. I've looked in a debugger at what happens when I click the submit button.

`index.php` and `menu.inc` direct control to `form.inc`, where `drupal_get_form` makes a call to `drupal_build_form`.

At this point `$form_state` seems to be being reconstructed from somewhere (the `cache_form` table?) as it certainly doesn't contain the settings I made to it during my earlier processing. (for e.g. I set `$form_state['foo'] = "bar";` which has now disappeared.)

Does anybody know how this works in more detail? Does form caching mean that it's impossible to submit Ajax-modified data to the submit handler?

# Answer
I received some help on Drupal.org about this... Jaypan's helpful reply is at https://www.drupal.org/node/2563045. I've posted a comment there to show how I got this working eventually.
> 1 votes

# Answer
You are changing the $form element in your ajax callback above. This is causing the issue. You should return the part of the form in the callback that should be inserted into the existing form. So in your callback function -

```
//Do your calculations
$form['tests']['#options'] = array('' => '- Select -') + $some_new_opts;

return $form['tests'];

```

Your Submit handler should be

```
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'go for it',
);

```

Adding your custom handler to the form

```
$form['#submit'][] = 'my_post_submit_function';

```
> 0 votes

---
Tags: forms, ajax
---


# Question
Title: Recover content from a deleted user and assign ownership to other user
There is a user that needs to be deleted but I need to keep his content. I want to know if there's a way to transfer the ownership of all of his content (nodes, userpoints, etc.) to another user? I tried views bulk operations, but there is no option there.

I know that I can delete the user and keep the content and give it to the Drupal anonymous user, but it´s possible to set up an specific user?

# Answer
Transferring ownership of nodes is a part of Drupal core's functionality. Outside of that, any other contrib module has to provide that functionality itself; Drupal core doesn't have a concept data ownership for contrib module data.

I've rarely seen a contrib module implement a data ownership transfer feature. For popular modules they might exist but it's not a given. For example, with userpoints there submodule called userpoints\_donations in the User Points Contributed modules project. However, it covers the use case of ***one user giving to another***, not transfership from an account set to expire.

You might be able to do this on a per module basis if you look at the data tables each module stores in its **.install** file. It would be pretty easy to look at each table for a `uid` column and perform a SQL UPDATE statement that changes any uid value from X to Y. If you know all the modules in question (with their respective data tables), it's quite feasible to build your own custom VBO operation that would automatically do the SQL queries for you.
> 0 votes

---
Tags: userpoints
---


# Question
Title: Allowing node creation/editing inside other node creation form
I have a custom content type *congress*, and inside the *congress* creation form, I want to allow the user to create and edit as many nodes as he wants of the custom type *event*.

How can I accomplish that? I've seen it's possible to create a field for selecting an existing node with node reference and node connect modules, but those do not allow me to create or edit nodes.

# Answer
> 5 votes
If you're not opposed to using Entity Reference module as instead of node reference, there's the Inline Entity Form module that does what you want:

> Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -\> children one (product display -\> products, order -\> line items, etc.), where the child entities are never managed outside the parent form.

---
Tags: nodes
---


# Question
Title: Google Analytics Reports with Background Process module (non-blocking http request)
Using Google Analytics Reports module latest version 7.x-3.0-beta2. I wanted to make this module to make requests in non-blocking fashion. Standard drupal makes it blocking fashion, which slows things down.

I started looking into Background Process module, which looks promising. Other option is HTTPRL module, which is similar to Background Process.

Right now I am using AJAX for fetching GA API reporting data, but I feel it's slow, because of how drupal\_http\_request works (synchronous, blocking way).

Is it possible to integrate non-blocking requests to fetch data from GA API without rewriting excellent Google Analytics Reports module?

# Answer
> 1 votes
This is not possible in the manner that you described. Sure you can make a chain of asynchronous calls, the browser AJAX request to Drupal then Drupal making a non-blocking HTTP request to the GA API. However, your AJAX call won't have data to use.

The Background Process & HTTPRL (check out the project page image) work by the request being one way; they are calling out to a URL that will trigger some background action that doesn't need to communicate back (e.g. some batch job or page crawler cron task). In your case, you need the GA API to communicate back with Drupal then Drupal to communicate back with the browser. There's no getting around that.

---
Tags: google-analytics, http-request
---


# Question
Title: Are 'active' and 'staging' required in config_directories?
Is it OK to delete the 'active' and 'staging' entries automatically created in settings.php? I don't plan on using them, but it's not clear to me whether some process might expect them to exist.

# Answer
Sadly, D8 will fail with the following exception, if you delete the *active* element from the array.

> Exception: The configuration directory type *active* does not exist. in config\_get\_config\_directory() (line 177 of core/includes/bootstrap.inc).

However, it doesn't seem to mind if you remove the `staging` entry. It's worth noting that `drush` 7 documentation says that the `staging` entry will be used by default when executing commands like `config-export` (drush 8, currently presents a nice menu listing all the `config_directories` instead of defaulting; but it's still in beta so the behavior may change).
> 1 votes

# Answer
The default.settings.php file contains the following comment:

> The staging directory is used for configuration imports; the active directory is not used by default, since the default storage for active configuration is the database rather than the file system (this can be changed; see "Active configuration settings" below).

In short:

* The *staging* directory is used only when importing configuration from the UI
* The *active* directory is not used by default from Drupal 8, which saves the configuration data in the database, like Drupal 7 did with the persistent variables

In both the cases, I would expect Drupal to correctly handle the case the global `$config_directories` is not set.
> 1 votes

---
Tags: 8, configuration
---


# Question
Title: Using Views to filter images based on taxonomy of page node
I have many image files with taxonomy associated with them. I have page nodes using the same taxonomy vocabulary. I want to create a Views block that filters the images displayed based on what that page uses for that vocabulary.

Fake example:

I have a page that is tagged with `carrots` and `broccoli`. I have image files tagged with the same terms. I want to place a Views block on the page and have that view only show images tagged with the same terms.

How do I do that?

# Answer
Create a views block.
Under Contextual filters, add Content: Has Taxonomy Term ID
Provide Default Value -\> Taxonomy Term ID from URL
Tick on 'Load default filter from node page, that's good for related taxonomy blocks' and tick your proper vocabulary.
> 0 votes

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


# Question
Title: How to change a node field when the output of a View changes?
I have a View *Top 3* that displays the 3 nodes with the highest average voting scores (I use Fivestar via comments on the nodes for voting). Every node has a field *Highest ranking*, that - as the name suggests - should store the highest ranking ever obtained in *Top 3*.

Now, the View *Top 3* also filters nodes that were created less than 5 days ago. I'm wondering how I can change the *Highest ranking* fields of the nodes in the top 3 when the top 3 changes. The above explanation should make clear that this can happen when

* a new comment with a vote has been created;
* an existing comment with a vote has been changed;
* a node is older than 5 days and is therefore banned from the top 3.

Which hooks can I use for this?

# Answer
Implement something like `hook_views_pre_render()` or `hook_views_post_execute()` and, every time your "Top 3" view is executed have your code iterate over the results and update the "Highest Ranking" field for each of the nodes in the top 3 as needed.

The only downside of this is that if your "Top 3" view is rarely ever executed then it's possible that a node could move into then back out of the Top 3 without the view ever being executed and thus without your code ever recording the node's presence in the top 3. If you want to try to avoid this you might implement hook\_cron and programmatically call your view every time cron is run.
> 0 votes

# Answer
It is a bit complex but I'll try to help get things started.

Since the view is just a dynamic collection of content it makes sense to monitor the content for the types of events/changes that affect the view result.

The module you'll need for this is Rules. I see from your profile that you have some experience here.

The Fivestar module doesn't appear to have any Rules integration so you may need to create a custom Rules condition to distinguish comments with votes. (Or maybe not - I'm just not familiar with the module.)

At its simplest, it boils down to triggering an action based on the criteria you have described above. The tricky part is checking the new vote count against the view result so that you can update the field accordingly.

One way you may be able to do this is to do a before-and-after check when a comment is saved or updated. Rules Bonus Pack (in particular the submodule "rules\_misc") has some Views-related additions that come in handy here.

A rough outline of a rule that alters (unsets?) the value of the field on "top 3" nodes before the comment is saved.

```
EVENT
  Before saving a comment (of type X)
ACTION
  Load a node list with Views (offered by Rules Bonus Pack)
  LOOP through list
    Fetch entity by id
    Set a data value (entity-fetched:fieldname)
  END LOOP

```

After the comment is saved, reset the field value on all "top 3" nodes which presumably have been recalculated based on this new data (the saved/updated comment).

```
EVENT
  After saving a comment (of type X)
  After updating an existing comment (of type X)
ACTION
  Load a node list with Views
  LOOP through list
    Fetch entity by id
    Set a data value (entity-fetched:fieldname)
  END LOOP

```

Note: You could do all of this by storing the result somewhere and checking on cron run or when a view is being built or a node is being viewed or what have you, but by attaching the action to the events that affect the result (comment being saved/updated) you ensure the change is implemented without delay.

For the third criteria ("a node is older than 5 days") you can set up another rule that checks a condition during a cron run and alters the field on all nodes that are older than 5 days. This will obviously have some delay (depending on how often your cron runs); maybe there's a better way but I can't think of one at the moment. You would probably use Views Bulk Operations for this. Also look at Rules Scheduler (a submodule of Rules). This isn't an uncommon scenario so a quick internet search should yield several methods/tutorials.

**Edit:** Added more specifics on how to implement with Rules (and Rules Bonus Pack) when a comment is created/updated.
> 0 votes

---
Tags: 7, views
---


title: View to show changes in node titles

text:
# Question
Title: View to show changes in node titles
In Drupal 7, I have a content type with revisioning turned on.

Is it possible to create a view that shows only nodes that have had the title changed?

Newest Title | Previous Title | Updated Date

# Answer
You probably can't get 100% exactly what you want but you can get very close. The problem is that we don't have a definitive history of the order in which revisions were created or edited. You may be able to make some assumptions if, for example, you know that you always force the creation of a new revision any time an edit is made, but I don't know enough of your business logic to speak to that. Regardless, I can get you most of the way there and build a view that shows nodes that currently have a title that differs from other revisions of the same node.

In my solution, you can end up with the following fields (amongst others):

* Current Title
* Previous title
* Date previously-titled-revision was last updated
* Date currently-titled revision was last updated

First, create a view based on Node Revisions.

When you do this I believe your view will, by default, have a relationship to the node table based on the vid. It will be called "Content revision: Content". You want to **remove** this. There's another, identically named relationship that you actually want to add instead; it has a description that reads "Content revision: Content, The revision NID of the content revision." **Add** that relationship.

After doing this you may find that you need to click on and re-save the settings for the "status" filter on the view as it will be set to use the old relationship. Or, if you want to see all nodes (even those that are un-published) just remove this filter entirely.

Now, add 2 fields to your view:

* **Content Revision: Title** -- this one probably already exists as it's added by default. This is the title of the revision and can be considered "previous title" for your use-case.
* **Content: Title** (this will use the relationship we just created) -- this is the title of whatever the "current" revision of the node is. This can be considered "current title" for your use-case.

At this point, you should be seeing a list of all revisions of all nodes, regardless of whether the title has ever changed. To limit the view to only show those where the title has changed we need to add a new filter called **Global: Fields comparison**. Configure the filter such that the "Left Field" is set to "Content revision: Title" and the "Right Field" is set to "Content: Title". Set the operator to "is not equal to".

Your view should now be more-or-less what you're looking for. Feel free to add the appropriate date fields, though none of them will be able to tell you exactly when the title itself was changed, per se.

Also note that this will give you one row per different title a node has ever had. So there may be multiple rows per node.
> 3 votes

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


# Question
Title: How can I delete old entries in locales_source
Drupal 7. I have used the t() function to translate many string in different languages. I used English as default language, and added t('This is a new string') all around my module files, template files, etc.

The problem is that I have changed the original string names several times, and in some instances, I didn't delete the "duplicate" entries, so there is garbage. Is there a way of listing or retrieving all the t() strings that I added? Maybe comparing with a fresh Drupal installation and exporting a template \*.po and using a program to compare the changes ?

Thanks!!!

# Answer
One way to get rid of unnecessary entries in `locales_source` is to run the following:

```
DELETE locales_source
FROM   locales_source
LEFT JOIN locales_target lt
using (lid) where lt.lid is null;

```

To get an idea of what this will remove from the table, you could check using:

```
SELECT count( * )
FROM locales_source
LEFT JOIN locales_target lt
USING ( lid ) WHERE lt.lid IS NULL;

```

I got the idea from : http://julian.pustkuchen.com/en/drupal-7-performance-blown-localessource-table

In my case, I had a lot of stale content in `locales_source`. I also had many pages where content was tagged as being translated, but the page included many call `t('...')` calls, which added unnecessary entries to the table. Long story short, I was able to safely remove over a million rows of data and site performance went from absolutely awful to humming along nicely.

YMMV, but it worked for me.
> 3 votes

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


# Question
Title: Displaying a Value while linking a Key with the Linked Field Module
I am using the linked field module to try to display a particular field as a link on a content page (I am not working within a View). The field is a select list with associated urls in the key. For example, the Value "Accounting Department" may have a key of "/drupal/accounting". I want the link to show "Accounting Department" but map the link to what is in the key. If I map to the field with this module, it tries to go to "/drupal/Accounting Department". Has anyone else attempted something like this or is there another module that will allow this?

# Answer
You need to configure the "token" view mode for the content type in question.

First, ensure you're set up to configure the "tokens" view mode separately from your other view modes.

1. Click to go to the "default" view mode:
2. Near the bottom, click "Custom display settings" and check "tokens", then save.
3. Now you will see "Tokens" in your list of view modes to configure:

Go to that page, find the field that contains the key you want and, in the drop-down in the format column, change it to "key".
> 1 votes

---
Tags: entities, navigation
---


# Question
Title: Is uploading/download executable files harmful in drupal?
In my site design, I have a field that is designed to hold an executable file (.exe, .bat, etc), for users to upload and download. I took pause as I was typing these extensions into the `Allowed file extensions` setting on the file field. Is this ok? What do I need to be aware of?

# Answer
> 6 votes
You'll want to make sure that your server is not configured to execute files of the given extensions in any way.

As a general precaution, you might also configure that file field to use the Private file system, which allows access to those files to be controlled by Drupal's permissioning system.

---
Tags: security, files
---


title: What is the best tagging widget?

text:
# Question
Title: What is the best tagging widget?
I was using the tagging module as my tagging widget until its status changed to `Maintenance status: Unsupported`. Now I'm looking for a replacement. After searching drupal.org I figured out there is not stable tagging widget module for D7:

1. nice\_tags only D6
2. tag\_editor only D6
3. active\_tags dev version and not works as expected
4. community\_tags tagging content in view mode not in add/edit form

Is there any other tagging widget which I overlooked?

# Answer
> 12 votes
Finally, I decided to use the Autocomplete Deluxe module as tagging widget.

> This is an enhanced autocomplete element, that uses the JQuery UI autocomplete. It will also implement a widget for taxonomy and lists.
> There is also an implementation for the References module: Autocomplete Deluxe for References.

# Answer
> 2 votes
Another module to look at is Chosen.

> Chosen uses the Chosen jQuery plugin to make your elements more user-friendly.

Note that it modifies the select list option, to achieve a tagging effect. Major drawback is you can't add new terms this way though.

# Answer
> 0 votes
You could use the Hierarchical Select module.

> This module defines the "hierarchical\_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.
>
> Hierarchical Select has the ability to save the entire lineage of a selection or only the "deepest" selection. You can configure it to force the user to make a selection as deep as possible in the tree, or allow the user to select an item anywhere in the tree. Levels can be labeled, you can configure limit the number of items that can be selected, configure a title for the dropbox, choose a site-wide animation delay, and so on.

# Answer
> 0 votes
You can take a look at MLTag. Uses machine learning algorithms to suggest tags based on your content and tagging history.

Link - https://www.drupal.org/project/mltag

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


# Question
Title: Pop-up calendar option does not display when I add Date field in webform
I am using Date and Calendar module. When I add a component to webform, I selected the Date field \> click Add. But I do not see the Pop-up calendar option. However, when I add a content type (structure \> Add content \> I see the Pop-up calendar option display for the date field).

How I can display the pop-up calendar option when I add Date component to webform?

# Answer
> 0 votes
The Popup Calendar option in Webform is entirely separate from the Date module, so it should always work regardless of whether you have installed Date module (or Date Popup module).

Make sure you've added a date component to your Webform, then under "Display" there is a checkbox for "Enable popup calendar". This option is enabled by default. Now a little calendar icon should appear next to your date component when viewing the node.

---
Tags: webforms
---


# Question
Title: Using Entity Metadata Wrapper to set/get value from custom field added via Field API to custom entity type
My question is related to: Using entity metadata wrapper with custom entity type

I know that I should inform EMW how to work with entity properties via hook\_entity\_property\_info\_alter

but what about custom fields added via Field API to custom entity. I'm trying to set value of that kind of field via EMW but after entity save, field (db table) is always empty.

# Answer
I've forgotten to set `fieldable => true` in hook\_entity\_info. Now EMW works
> 1 votes

---
Tags: 7, entities
---


# Question
Title: Tracking User's Location at a certain point
I've installed the Time Tracker module.

I need to track user's location when the user clicks on "Start Timer" AND when the user clicks "Stop Timer". Please help or point me in the right direction. I tried to use rules but I didn't know where to begin.

# Answer
> 0 votes
You can append a different query string to each click, which will allow you to track each one individually. Lets say your "Start Timer" is at mysite.com/start\_timer (using ajax). You can create several url's with a query string that lead to the buttons. Ex:

mysite.com/start\_timer (using Ajax)

mysite.com/end\_timer (using Ajax)

Then you can use Google Analitics Event Tracking Module which will do your work for tracking easily.

Enjoy !

---
Tags: rules, location
---


title: overall Information of content

text:
# Question
Title: overall Information of content
I have created content on 30/8/15 and the same created content is edited by other user on 1/9/15, when I go check in the dashboard or if i create view and see the edited only i could see, but in my case i want to see overall like when the content is created and by whom its created and also by whom edited?on what date for that particular content I want to see it in a view. how to achieve this please can any one suggest me?

# Answer
First if you haven't enabled revisions for your content type, please enable like below:

admin/structure/types/manage/\[your-content-type\]

After that you need to create view to show revisions like below:

This will help you to achieve all information of event on node.

Thanks!
> 2 votes

---
Tags: nodes
---


# Question
Title: Value of the input is not preserved when it is an HTML array
Suppose, we have a form, containing 3 elements:

1. Checkbox with special name 'name\[attached\]', indicating that it is a part of an array of checkboxes.
2. Text input
3. Submit button

## Code

```
function bundles_test_form($form, &$form_state)
{
    $form['name[attached]'] = array(
        '#type' => 'checkbox',
        '#required' => false,
        '#attributes' => array('name' => 'name[attached]'),
        );

    $form['date'] = array(
        '#type' => 'textfield',
        '#required' => false,
        );

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

    return $form;
}

function bundles_test_form_validate($form, &$form_state)
{
    if (isset($form_state['input']['name']['attached']))
    {
        if ($form_state['input']['date'] === '')
        {
            form_set_error("date", 'date is required');
        }
    }
}

```

## Question

When the form throws an error, the checkbox must be checked, but it is not. When I change the name to "name" or anything that it not the array, it works correctly. So the error is caused by the non-standard name of the input.

# Answer
IMO this should work

```
    function mm_definition_of_the_form($form, &$form_state) {
      //other code
      $form_state['rebuild'] = TRUE;

      if (isset($form_state['check_field'])) {
        //set default value of the field
      }
    }

    function mm_definition_of_the_form_validate(&$form, &$form_state) {
      //if is error
      $form_state['check_field'] = TRUE;
    }

```
> 0 votes

---
Tags: forms
---


title: Deploying to live and available modules

text:
# Question
Title: Deploying to live and available modules
In Drupal 8 you can export configuration and move that to a production server. In `core.extensions.yml` there is an exported list of the enabled modules. If on development I have devel and other auxiliary modules installed these are added in that file but I do not want that to be part of the production environment.

Is there a switch to do that? How can `master` module from Drupal 7 replicated here?

# Answer
I think there is not really a good option for this yet.

It's tricky, because you can't just override the config and have those modules enabled since they also provide their config (which would and install/uninstall processes that can't be skipped. In fact, providing config overrides for core.extension is explicitly prevented.

Maybe someone will come up with a good way to do this, I currently don't really know how that should work.
> 0 votes

---
Tags: 8
---


# Question
Title: What are dependencies in the context of a user role in Drupal 8?
In the process of wrapping my head around Drupal 8's configuration system (which is awesome, by the way), I came across this:

**YAML file** (from *core/modules/user/config/install/user.role.authenticated.yml*)

```
id: authenticated
label: 'Authenticated user'
weight: 1
langcode: en
status: true
is_admin: false
dependencies: {  }

```

Now of course I understand module dependencies, but what might be set here as a dependency for a user role configurable and what would it mean?

Thanks!

# Answer
> 4 votes
As Ivan Jaros said, all config entities can have dependencies on modules and other config entities, both automatically derived based on code (e.g, a field depends on its field storage and entity bundle it is added) and manually set (in an enforced sub-array with the same structure)

Dependencies ensure that the required dependencies are installed and they are installed in the right order. Which is important if you import a new node type with fields, display configurations, views that list them and so on.

User roles currently don't have automatically derived dependencies, but they actually should have. They should depend on the modules that provide the used permissions, which is a bit tricky since permissions don't give you that information especially not for dynamic ones that depend on node types, filter formats and so on. That's why the key is always empty for them.

We should open a core issue to try and track this better, that would allow roles to clean up permissions when e.g. a node type is deleted or a module is installed. But it's not a major problem since nothing happens if those permissions don't exist anymore.. it's just a string and if nothing asks for it, then nothing happens with it. The only problematic thing is that you a) end up with cruft in those config objects and b) the permissions could get active again when you e.g. delete a node type and add again with the same name. You might not expect your permissions configurations to survive that.

---
Tags: 8, users, configuration
---


# Question
Title: How can I make a field of "Content: Type" visible to users who do not have the "Administer content types" permission?
I am trying to create a view which shows new posts of certain content types, including the name of the content type. So, e.g., "New How To: Displaying Content Type Fields in Views". Here are the fields:

* Content: Title \[hidden\]
* Content: Type \[hidden\]
* Global: Custom Text
* Content: Authored on

The "Global: Custom Text" field is a combination of the first two fields as "New {{ type }}: {{ title }}". The issue I have is this: The "Type" field appears blank for anonymous users unless I grant them the "Administer content types" permission. This is not an acceptable solution.

Is there a clean way to display this for anonymous users? Maybe a permission I'm missing? Relatedly, is there any danger in allowing users to see this?

I'm working with Drupal 8.0.0-beta14 (the latest at the time of this question). The code for the exported view is below if it helps.

```
uuid: 48ef9d3a-8278-4bc5-b13e-62eec03bad09
langcode: en
status: true
dependencies:
  config:
    - node.type.blog_post
    - node.type.how_to
  module:
    - node
    - user
id: news_items
label: 'News Items'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
  default:
    display_plugin: default
    id: default
    display_title: Master
    position: 0
    display_options:
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: tag
        options: {  }
      query:
        type: views_query
        options:
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_comment: ''
          query_tags: {  }
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      pager:
        type: full
        options:
          items_per_page: 4
          offset: 0
          id: 0
          total_pages: null
          tags:
            previous: '<<'
            next: '>>'
            first: '|<'
            last: '>|'
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
          quantity: 3
      style:
        type: html_list
        options:
          grouping: {  }
          row_class: list-group-item
          default_row_class: true
          type: ul
          wrapper_class: ''
          class: list-group
      row:
        type: fields
      fields:
        title:
          id: title
          table: node_field_data
          field: title
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: true
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: false
            ellipsis: false
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: value
          type: string
          settings:
            link_to_entity: true
          group_column: value
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: node
          entity_field: title
          plugin_id: field
        type:
          id: type
          table: node_field_data
          field: type
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: true
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          click_sort_column: target_id
          type: entity_reference_label
          settings:
            link: false
          group_column: target_id
          group_columns: {  }
          group_rows: true
          delta_limit: 0
          delta_offset: 0
          delta_reversed: false
          delta_first_last: false
          multi_type: separator
          separator: ', '
          field_api_classes: false
          entity_type: node
          entity_field: type
          plugin_id: field
        nothing:
          id: nothing
          table: views
          field: nothing
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: true
            text: 'New {{ type }}: {{ title }}'
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: false
          plugin_id: custom
        created:
          id: created
          table: node_field_data
          field: created
          relationship: none
          group_type: group
          admin_label: ''
          label: ''
          exclude: false
          alter:
            alter_text: false
            text: ''
            make_link: false
            path: ''
            absolute: false
            external: false
            replace_spaces: false
            path_case: none
            trim_whitespace: false
            alt: ''
            rel: ''
            link_class: ''
            prefix: ''
            suffix: ''
            target: ''
            nl2br: false
            max_length: 0
            word_boundary: true
            ellipsis: true
            more_link: false
            more_link_text: ''
            more_link_path: ''
            strip_tags: false
            trim: false
            preserve_tags: ''
            html: false
          element_type: ''
          element_class: ''
          element_label_type: ''
          element_label_class: ''
          element_label_colon: false
          element_wrapper_type: ''
          element_wrapper_class: ''
          element_default_classes: true
          empty: ''
          hide_empty: false
          empty_zero: false
          hide_alter_empty: true
          date_format: custom
          custom_date_format: 'Y-M-d g:i:s A'
          timezone: America/Toronto
          entity_type: node
          entity_field: created
          plugin_id: date
      filters:
        status:
          value: true
          table: node_field_data
          field: status
          plugin_id: boolean
          entity_type: node
          entity_field: status
          id: status
          expose:
            operator: ''
          group: 1
        type:
          id: type
          table: node_field_data
          field: type
          relationship: none
          group_type: group
          admin_label: ''
          operator: in
          value:
            blog_post: blog_post
            how_to: how_to
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
            reduce: false
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
          entity_type: node
          entity_field: type
          plugin_id: bundle
      sorts:
        created:
          id: created
          table: node_field_data
          field: created
          order: DESC
          entity_type: node
          entity_field: created
          plugin_id: date
          relationship: none
          group_type: group
          admin_label: ''
          exposed: false
          expose:
            label: ''
          granularity: second
      title: 'News Items'
      header: {  }
      footer: {  }
      empty: {  }
      relationships: {  }
      arguments: {  }
      display_extenders: {  }
      css_class: ''
      use_ajax: true
    cache_metadata:
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
        - 'user.node_grants:view'
        - user.permissions
      cacheable: false
  block_1:
    display_plugin: block
    id: block_1
    display_title: Block
    position: 1
    display_options:
      display_extenders: {  }
    cache_metadata:
      contexts:
        - 'languages:language_content'
        - 'languages:language_interface'
        - url.query_args
        - 'user.node_grants:view'
        - user.permissions
      cacheable: false

```

# Answer
> 0 votes
Sounds like there is a field permission on the type field that prevents view access.

Not quite sure where that happens, actually, that would be in `NodeAccessControlHandler::checkFieldAccess()`, as you can see, that for example limits edit access on certain fields, but there's nothing about type, so that *should* be editable.

Ah.. maybe the field checks view access of the referenced entity, and node types aren't viewable by anonymous users, so it doesn't display it.

We have similar problems with e.g. referenced users, since Drupal doesn't have a generic concept of a "view label" access.

You could try to open a core issue and in NodeTypeAccessControlHandler::checkAccess(), allow view access if you have the access content permission or so, but it's tricky.. since that will e.g. also allow access to all values in it (like the settings for it), in case there is a generic check for it (e.g. REST).

---
Tags: views, 8
---


title: Cannot clone an aegir site

text:
# Question
Title: Cannot clone an aegir site
I am getting this error while cloning the site on aegir

> Unknown option: --profile. See `drush help provision-backup` for available \>options. To suppress this error, add the option --strict=0. \[2.39 sec, 21.19 MB\]

I am using aegir3 on ubuntu 14.04.4. Can anyone please help me solve this. I have searched on web but there is no solution regarding this issue. This issue also occurs while migrating.

# Answer
> 1 votes
As I mentioned in IRC, the following work-around should resolve that particular issue:

1. Login to the server via ssh.
2. Become the 'aegir' user (`sudo -u aegir -s -H`)
3. Create a file call /var/aegir/.drushrc.php with the following contents:

```
 <?php
 $options['strict'] = 0;

```

That said, this appears to be a bug, though not one that has been reported previously. If anyone else stumbles across this issue, please file a bug report at https://www.drupal.org/node/add/project-issue/provision.

---
Tags: multi-sites, aegir
---


# Question
Title: How to customize the markup of radio buttons in the edit/create node view?
So I have a content type with several fields. One field is a set of two radio buttons. The output code while content creation/moderation looks like this:

```
<div id="edit-group-content-access" class="field-type-list-integer field-name-group-content-access field-widget-options-buttons form-wrapper">
<div class="form-item form-type-radios form-item-group-content-access-und">
    <label for="edit-group-content-access-und">Group content visibility <span title="Diese Angabe wird benötigt." class="form-required">*</span></label>
    <div class="form-radios" id="edit-group-content-access-und">
        <div class="form-item form-type-radio form-item-group-content-access-und">
            <input type="radio" class="form-radio" checked="checked" value="1" name="group_content_access[und]" id="edit-group-content-access-und-1">
            <label for="edit-group-content-access-und-1" class="option">Public - accessible to all site users </label>
        </div>
        <div class="form-item form-type-radio form-item-group-content-access-und">
            <input type="radio" class="form-radio" value="2" name="group_content_access[und]" id="edit-group-content-access-und-2">
            <label for="edit-group-content-access-und-2" class="option">Private - accessible only to group members </label>
        </div>
    </div>
</div>

```

Now I want it rather to be something like this:

```
<div class="form-radios" id="edit-group-content-access-und">
  <input type="radio" class="switch-input" name="group_content_access[und]" value="1" id="Public" checked>
  <label for="edit-group-content-access-und-1" class="switch-label switch-label-off">Public</label>
  <input type="radio" class="switch-input" name="group_content_access[und]" value="2" id="Private">
  <label for="edit-group-content-access-und-2" class="switch-label switch-label-on">Private</label>
  <span class="switch-selection"></span>
</div>

```

How can I change this markup? (I run Display suite and tried to ajust it somehow with DS settings; did not work out.)

---

## Troubleshooting

### Issue #1

In how far is `$output` not used anymore for radio buttons?

### Issue #2

How do I add `<span class="switch-selection"></span>` after my second radio-button-label? (See the example above.)

### Issue #3

The front page shows the following message.

> Notice: Undefined variable: output in themename\_form\_element() (line 309 of D:\root\sites\all\themes\themename\template.php).

# Answer
You can alter the output by overriding the following Drupal theme functions: theme\_form\_element, theme\_radios, and theme\_radio. (You won't need `theme_radio` unless you want to make changes to the `<input>` tag.)

Copy these functions into your theme's template.php file and replace "theme" in the function name with the name of your theme. Customize as needed. You will have to clear your cache in order for the changes to take affect.

In `theme_form_element()`, if you want to limit your changes to radio elements, you can add this condition:

```
if ($element['#type'] == 'radios' || $element['#type'] == 'radio') {
  // your stripped down mark-up here
}
else {
  // default mark-up
}

```

You can also check against other criteria such as `#name` and `#id`:

```
if (strpos($element['#id'], 'edit-group-content-access') !== FALSE) {
  // This form element has an id of 'edit-group-content-access-und-1' or 'edit-group-content-access-und-2'.
}

```

A real world example that only prints the wrapper for elements that *ARE NOT* radio elements (only alter the code that is shown and leave the rest as-is):

BEFORE

```
function mytheme_form_element($variables) {
  // ...
  $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  // ...
  $output .= "</div>\n";
  // ...
}

```

AFTER

```
function mytheme_form_element($variables) {
  // ...
  $output = '';
  if ($element['#type'] != 'radios' && $element['#type'] != 'radio') {
    $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  }
  // ...
  if ($element['#type'] != 'radios' && $element['#type'] != 'radio') {
    $output .= "</div>\n";
  }
  // ...
}

```

Bonus tip :): If you just want to alter the attributes of the wrapper, not remove it entirely, see this example.
> 2 votes

---
Tags: forms, display-suite
---


# Question
Title: why does drush tag 8.0.0-beta14 returns all zero for config core.extensions
After a fresh install of d8 with several core modules activated (block, breakpoint, database logging, field, filter, internal page cache, node, system, toolbar, update manager, user, views, views ui), extracting the config indicates that all the above are off:

```
# drush8 @myproject.dev config-get core.extension
module:
  block: 0
  breakpoint: 0
  config: 0
  datetime: 0
  dblog: 0
  entity_reference: 0
  field: 0
  file: 0
  filter: 0
  image: 0
  node: 0
  page_cache: 0
  system: 0
  text: 0
  toolbar: 0
  update: 0
  user: 0
  views: 0
  views_ui: 0
  minimal: 1000
theme:
  stark: 0
  classy: 0
  seven: 0

```

`stark` is, in fact, the default activated theme and `seven` is the admin theme.

The plan is to dump the config from the dev server and then import it into the stage server; but this is tricky if the config dump from dev is "blank."

Is this what's supposed to happen?

I'm using drupal version 8.0.0-beta12, and drush version 8.0.0-beta14.

# Answer
The numeric values in core.extension are the module weight; if a module is disabled, then it does not appear in the list at all.
> 3 votes

---
Tags: drush, 8, configuration
---


# Question
Title: Custom user profile titles interfering with user views block
I'm using this function to replace the titles on user pages with a user text field:

```
function MYMODULE_user_view($account, $view_mode, $langcode) {
  $wrapper = entity_metadata_wrapper('user', $account);
  $auth_name = $wrapper->field_account_auth_name->value();
  if ($auth_name) {
    drupal_set_title('Profile overview for ' . $auth_name;
  } else {
    drupal_set_title('Profile overview for ' . $account->name);
  }
}

```

It works as it should, but when I add a view block with user entities it makes every page have the same title. It's `Profile overview for ' . $auth_name;` for the first user with a non-empty field\_account\_auth\_name. If I delete that user the next user takes its place. This is for all pages too, not just ones with the block in it.

If it matters I'm using this function

```
  function MYMODULE_preprocess_user_profile(&$vars) {
    if ($vars['elements']['#view_mode'] == 'auth') {
      $vars['theme_hook_suggestions'][] = 'user_profile__auth';
    }
  }

```

with a user entity "auth" I created using Entity View Mode, with this in user-profile--auth.tpl:

```
<div class="authProfile"<?php print $attributes; ?>>
  <?php print render($user_profile); ?>
</div>

```

and setting auth as the view mode in the view block. But the title problem happens with the user account view mode as well.

# Answer
You could check the url using the arg function and only set the title if the current page is a user/\* page. You could try something like the following.

```
function MYMODULE_user_view($account, $view_mode, $langcode) {
  if (arg(0) == 'user') {
    $wrapper = entity_metadata_wrapper('user', $account);
    $auth_name = $wrapper->field_account_auth_name->value();
    if ($auth_name) {
      drupal_set_title('Profile overview for ' . $auth_name;
    } else {
      drupal_set_title('Profile overview for ' . $account->name);
    }
  }
}

```
> 0 votes

---
Tags: views, theming, entities, users
---


# Question
Title: How can I make Rules react to `User has logged in` when user logs in through CAS?
I want to execute some php code when users log in, so I'm experimenting with the `Rules` module. I have it configured to fire a function of mine when a user logs in and it works fine, but it only works if the user logs in through Drupal. I am using CAS to authenticate users (thanks to the CAS module) and if a user logs in with CAS, the function never gets called. Is there any way to solve this?

Here is the function which is successfully called when a user logs in through Drupal:

**myModuleName.rules.inc**

```
function myModuleName_rules_action_info () {
    return array(
        'hello_rules_world' => array(
            'label' => "Print Hello World to error.log"
        )
    );
}

function hello_rules_world () {
    error_log("Hello Rules World!");
}

```

And here is a screenshot of the configuration:

**UPDATE:** I ended up using `hook_user_login`, which detects all logins without problem:

**myModuleName.module**

```
function myModuleName_user_login (&$edit, $account) {
    my_user_login_function($account);
}

```

# Answer
I ended up using `hook_user_login`, which detects all logins without problem:

```
myModuleName.module

function myModuleName_user_login (&$edit, $account) {
    my_user_login_function($account);
}

```
> 0 votes

---
Tags: 7, rules, users
---


title: Spam users and rules

text:
# Question
Title: Spam users and rules
I'm getting swamped by spam users. Can I use rules to automatically delete users that 1) don't have content/comments, 2) have never activated in a few weeks, and 3) have only activated the same day they created their account, but haven't posted content/comments?

# Answer
> 3 votes
To get rid of inactive users, have a look at the Inactive User module.

User Stats will keep track of the IP's used by the various users.

The Spambot module is quite effective at blocking bots which create the inactive accounts. If you can take the time, it will let you report and delete spam postings to help block future attempts.

However nothing will stop them. One of my sites just came under attack over the weekend. Over 600 new user registrations in less than 12 hours (at times 3 per minute). I checked the IP's and found that I had multiple accounts created from a few IP's (between 15 and 45 users from the same IP). Manually blocking the IP's involved at **/admin/config/people/ip-blocking** and deleting the accounts was the only way to stop the attack.

Good luck.

# Answer
> 1 votes
Install honeypot module and also create a rules which banned the IP when it fails on honeypot.

Honeypot have a rules integration, just create a rules and action to banned the IP when it fails on honeypot.

On honeypot, create a meaningful field name like "country" or "city"

I combat the spam bot for a week, and finally found this method to block them. My banned list was growing larger and larger in the database and then I analyze the banned IP addresses and create IP ranges banned in .htaccess file.

This way, you have multiple layer of security.

Good luck

---
Tags: 7, users, rules
---


# Question
Title: How to programmatically refresh the current page?
I need to customize a module and after an **if statement check**, refresh the page:

So what I need is to refresh the page right after this and print out a success message.

# Answer
What you can do is still use Rules for this.

1. Go to your custom rule
2. Under the Actions section, click Add action
3. For *Select the action to add*, choose Page redirect.
4. For *URL*, place the internal or absolute path to where the page you want to go to a.k.a. be refreshed.
5. Then save the action. This solves your problem to refresh the page.
6. Now we add another action to display a message, click the Add action link again.
7. For *Select the action to add*, choose Show a message on the site.
8. Then place your message then Save.

This way, your actions based on an event is configurable just with Rules. This also opens an opportunity to convert your custom code to respond using Rule Events like to trigger the rule after a node is saved and etc.

**Update**

This is an option to programatically do the above method.

1. After the rule invoke method, add the drupal\_set\_message function
2. After the drupal\_set\_message method, you would need to add the drupal\_goto function which you will pass a Drupal path or a full URL.
> 3 votes

---
Tags: 7, rules
---


# Question
Title: Views image field linked with nofollow attribute
I have a view that renders a list of articles. Each article has a title, a main image and a trimmed part of its body.

I have both the title and the image are linked to the content i.e the article's details. This is not good practice for SEO. I want to add the attribute `rel="nofollow"` to the links to the content of the image field.

I have tried to search for a module that may do this task but I could not find any.

Also, I have tried to use `REWRITE RESULTS` like the following:

```
<div class="field-image"><a href="[view_node]" rel="nofollow">[field_image]</a></div>

```

However, it rendered wrong content because `[view_node]` tokens gives `Read More` html hyperlink.

By this way, to keep SEO, I have only to remove linking from image and this is not a suitable choice.

Is there any suggestion for modules do that or any way to rewrite the image field to be linked?

The following screen shot may offer extra visual details about my issue:

# Answer
Add `Nid` field , `exclude to display` then in `rewrite` section instead

`<div class="field-image"><a href="[view_node]" rel="nofollow">[field_image]</a></div>`

try

`<div class="field-image"><a href="node/[nid]" rel="nofollow">[field_image]</a></div>`
> 1 votes

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


title: Using batch api without a form

text:
# Question
Title: Using batch api without a form
I have a page which uses the form api. When I go to that page via hook\_menu I want to run a batch script.

I have looked at the batch example module and have come up with the following:

My page code

```
...

batch_set(my_batch());
die(); // removing this has no affect

...

```

Rest of the code

```
function my_batch() {
  $max = 10000;
  $increment = 1000;

  drupal_set_message(t('Creating batch'));

  $operations = array();

  for ($i = 0; $i < $max; $i = $i + $increment) {
    $operations[] = array(
      'batch_example_op_1',
      array(
        $i,
        $increment
      ),
    );
  }
  $batch = array(
    'operations' => $operations,
    'finished' => 'batch_example_finished',
  );
  return $batch;
}

/**
 * Batch operation for batch 1: load a node.
 *
 * This is the function that is called on each operation in batch 1.
 */
function batch_example_op_1($count, $increment) {
  drupal_set_message('Count is : ' . $count);
  $context['results'][] = time();
}

function batch_example_finished($success, $results, $operations) {
  if ($success) {
    drupal_set_message('All done');
  }
  else {
    drupal_set_message('Error');
  }
}

```

Currently the `$operations` array is being created and is being passed to `batch_set()` then nothing else is happening.

# Answer
> 4 votes
Based from the first sample code found in Drupal's Batch API page, it says,

> If this function was called from a form submit handler, stop here, FAPI will handle calling batch\_process(). If not called from a submit handler, add the following, noting the url the user should be sent to once the batch is finished.

And that we need to add the `batch_process('node/1');` (still based from the sample code). So you just need to add this line of code with the Drupal path where you want the user to be redirected after the batch process after the `batch_set()` line.

The `die()` line also isn't needed anymore based on the sample code. I have also tested your code on my local D7 site with the batch\_process() addition.

**Unrelated Update**

In your for loop declaration `for ($i = 0; $i < $max; $i = $i + $increment)`, I noticed that the afterthought section doesn't increment the loop because the variables `$i` and `$increment` has no incremental operation.

---
Tags: 7, batch-operations
---


# Question
Title: How to implement invitations limits per user when using the Invite Module?
So, basically, I'm trying to create a private invitation-only forum. I'm using the invite module.

Is possible to set invitation-restrictions? For example, each user can only invite a total of 3 users, or a user can only send one invite per month?

Also, do unclaimed sent invites expire?

# Answer
> 1 votes
# Invitation expiration

Quote from the Community documentation about the Invite module (from its installation instructions):

> ***Invitation expiry***: Set the expiry period for user invitations, in days (default select up to 365 days).

So the answer to your 2nd question ***do unclaimed sent invites expire?*** is YES. That's what's stated also in comment #3 of the issue about Set expiry date to never.

# Setting invitation restrictions

Looks like this feature "used to be available in a prior version of the module". And according to comment #3 of the issue about Limit invitation per user/role, it should be back some day.

While waiting for that to happen, you may want to use some type of Rules integration. Such as the solution as included in the issue about Rules integration for D7. It includes a patch for the 7.x-2.x version (status "RTBC"). If you're using 7.x-4.x however, then note the issue status "Needs work" ...

# Answer
> 0 votes
While the invite module doesn't provide this functionality, per se, it does provide a series of API hooks that will allow you to extend functionality. In your use case, you need to keep track of your user quota as invites are sent/accepted with `hook_invite_send()` / `hook_invite_accept()`.

You'll also need to `hook_form_alter()` the `invite_form()` so that it has a validation function that rejects users who go over their quota.

---
Tags: 7
---


# Question
Title: How to programmatically change settings of input filters and activate them?
I'm looking for a way to programmatically change the settings of an input filter and activate it in Drupal 7. Let's take the Footnotes module as an example: It adds a new input filter that can be activated on input formats. I can navigate to `admin/config/content/formats/2` to edit my "Full HTML" input format and there activate the Footnote filter and configure it. But how can I achieve that programmatically?

My first guess was to load the input format using filter\_format\_load(), change some values and then do a filter\_format\_save(). But in the object that I get from filter\_format\_load(), there are no input filters, i.e. `$format->filters` doesn't exist.

I can get all available filters using filter\_list\_format() and I believe I could change some values there. But then again, I can't find a way to save those settings.

# Answer
> 7 votes
If you read the API page for the functions you mentioned in your question, you can easily see that there is a bug(or a feature) that it does not load populate `$filter->filters` indeed.

For a workaround, you could do something like this, with the help of `filter_list_format()`

```
$format_id = 'full_html';
$filter_id = 'your_filter';

```

First, load the format object

```
$format = filter_format_load($format_id);

```

Now, since we do not have the `$filter->filters` populated, we do so by loading the currently enabled filters.

```
$filters = filter_list_format($format_id);
foreach ($filters as $filter_id => $filter_opts) { //Convert to an array, which is expected by the save function.
  $filters[$filter_id] = (array) $filter_opts;
}

```

You can now make changes in the filter that you are interested in.

```
$filters[$filter_id]['status'] = TRUE; //Enable.
$filters[$filter_id]['settings']['something'] = 'foobar';

```

Inject filters to the format we have already loaded.

```
$format->filters = $filters;

```

Save!!

```
filter_format_save($format);

```

---
Tags: 7, input-formats
---


# Question
Title: Adding child elements to checkbox/radio form elements
How can I add child elements to a checkbox/radio element? I have the following code.

```
$form['search_product'] = array(
    '#type' => 'radio',
    '#title' => t('Product'),
);

$form['search_product']['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);

```

"search\_attributes" checkboxes don't show up on the form, and I have only one radio.

# Answer
I don't believe you can make a radio button a "parent".

Here's an example of using radios, checkboxes, and fieldsets.

http://api.drupal.org/api/examples/form\_example!form\_example\_states.inc/function/form\_example\_states\_form/7

You might take a look at http://api.drupal.org/api/drupal/developer!topics!forms\_api\_reference.html/7#container

Try removing search\_attributes from search\_product

```
$form['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);

```
> 1 votes

# Answer
I faced the same problem. To get checkboxes to be rendered, i'd suggest you go about it like so:

```
$form['search_product']['search_attributes'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
        'name' => t('by Name'),
        'model' => t('by Model'),
        'catalog_no' => t('by Catalogue No.'),
        'manufacturer' => t('by Manufacturer'),
        'description' => t('by Description'),
    ),
);
$form['search_product']['search_attributes'] = form_process_checkboxes($form['search_product']['search_attributes']);

```
> 0 votes

---
Tags: 7, forms
---


# Question
Title: Should i use field.tpl.php or Display suite to add my own classes to fields?
I want to get rid of the default classes and add my own to the fields. I was always using field.tpl.php but i've read some tutorials where people are doing this with Display Suite. So should i do this via field.tpl.php or Display suite?

# Answer
> 3 votes
It's matter of opinion, really. I'm using DS and it works fine, but it might have disadvantages later on, because I will have to export my settings to code with Features.

Also, DS isn't your only option - you can also try:

and others. Which depends on your other needs - for example, are you planning to use DS multiple display modes handling?

---
Tags: entities, theming
---


# Question
Title: Conditionally change the image field style and wrapping it in a div
The Article content type has been classified by taxonomy vocab Topic, where each Article's node has one topic.

For some usability and design requirements, I want Articles belongs to a specific topic to render the image field in different image style when it is on the `full` display mode.

I used the code in `node--article.tpl.php`:

```
if ($node->field_topic['und'][0]['tid'] == 154){
     // In some preprocessor...
    $images = field_get_items('node', $node, 'field_image');
    if(!empty($images)) {
      $image = field_view_value('node', $node, 'field_image', $images[0], array(
        'type' => 'image',
        'settings' => array(
          'image_style' => '200x260',
          'attributes' => array('class'=>'center-text')
        )
      ));
    }
    // Testing wrapping the image
    $variables['image'] = "----".$image."----";

    // Now, in your .tpl.php
     $content['field_image'] =  $image;
     }
  print render($content)

```

The above code renders the image with HTML code like the following:

```
<img typeof="foaf:Image" src="http://example.com/path/to/image/10_0.jpg?itok=COlIqejP" width="200" height="260">

```

However, it works fine but has two limitations:

1- I could not able to figure out how to enclose the image inside a `div` with css class to style it using CSS. The img tag is supplied only i.e without any wrapping divs or spans!

2- Using it from `node--article.tpl.php` is not recommended and I have a custom module, but I don't know the suitable node's hook that allows me to perform this task.

# Answer
You can set wrapper for it with simple way instead

`print render($content);`

just use

`print '<div class="my-wrapper">'.render($content['field_image']).'</div>`;

and for second limitation if you have not `$node` just need load it with `node_load` ( if you have nid)

So before your code

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

```
> 1 votes

---
Tags: 7, nodes, hooks, media, entities
---


# Question
Title: Language switcher shows wrong language on front page after detection by browser settings
Content and interface are displayed correctly but the language switcher shows the default language when the language negotiation is set to these options:

* URL (language prefix)
* Browser
* Standard

Means: Browser detection leads to displaying content in german for example, but **the language switcher itself shows still "english" as selected**. Even when clicking on it the language still is german.

This only happens on the front page, on other paths the prefix takes effect and the switcher shows the correct, selected language.

Any ideas how to fix this? Thanks in advance!

EDIT: The frontpage is designed with translated blocks only, there's no node to point the multilingual variable to. For multilingual we have following modules installed and used: \- Internationalization (i18n) \- Block languages (i18\_block) \- Multilingual content (i18n\_node) \- String translation (i18n\_string)

For each language there are several "standalone" blocks, meaning not translated via the block translation option. Visibility is set through these settings:

# Answer
> 0 votes
It could well be that your issue is due to the fact that you do not have any nodes (Drupal without ANY nodes ... go figure ... a **C**MS without any "real" **Content**). So to get it to work you may have to make Drupal give "a few nodes" (i.e. 1 for each language ...).

If you agree, and based on what is described in Multi-language website and language switcher in front page, you may want to try if the steps below, or a subset of it, resolve your issue (probably replacing all 'IT' by something like 'GE' for 'German'):

1. Assign "path prefix only" to the language settings.
2. Assign the prefix EN for English.
3. Created an IT front page (e.g. `node/1`), chose language IT and leave the menu link title empty in the primary links (you probably want to leave the body empty also).
4. Create the EN front page (e.g. `node/2`), chose language EN and leave the menu link title empty in the primary links as well. You probably want to leave the body empty also, though for testing purposes you may temporary want to put some visible content in it also.
5. In both the IT page and the EN page check "promoted to front page" in the publishing options.
6. Not sure if you need this step also (first try by skipping this step): in `Administer > Site building > Menus > Primary links`, create a menu item for "Home" and assign its path to "front", parent item "primary links" and language "all languages".
7. In "Site information", put "node" as default front page.
8. Check if your language switcher now works fine: verify if it changes the content from `node/1` to `node/2` (each of them with their related blocks to be shown) based on selected language. If you also performed step 6, then verify if the primary link "Home" always goes to the corresponding front page (and related blocks).

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


# Question
Title: Can Drupal 8-compatible Drush be installed in Windows?
Has anyone had any luck upgrading from Drush 6 to 7 on a windows machine? I feel like I'm beating my head against a wall trying to get this done. I want/need to use Omega 4 and I need Drush 7 to do so. Also, if I ever want to update my websites to Drupal 8, I will need Drush 7. Any direction/advice would be great!

Edit by @othermachines: Drush 8 is now recommended for Drupal 8 development.

# Answer
> 3 votes
Although it's a year and a half since this question was posted, as we get closer to a production release of Drupal 8 I can see it getting a few hits. So here's my answer...

### Yes, it certainly can!

Although as of this writing it appears Drush 8.x (in particular the latest dev on branch master) is the recommended version for Drupal 8 development.

See: Drush Installation/Upgrading instructions

I'm running WampServer 2.5 (PHP 5.6.13RC1, MySQL 5.6.17, Apache 2.4.9) on Windows 8.1 and use Git Bash shell from the Git for Windows installation. I have Composer 1.0-dev set up globally.

I was able to upgrade successfully1 following the first installation method on this page, *Composer - One Drush for all Projects*.

### Steps

1. Install from the command line:

`$ composer global require drush/drush:dev-master`
2. Modify the path to Drush in your system environment variables (here's a helper). On my system, Drush was installed in `c:\Users\Username\AppData\Roaming\Composer\vendor\drush\drush`.
3. Reboot Windows

### Troubleshooting: Check loaded php.ini

The only problem that cropped up post-install was that the PHP settings being loaded by the CLI (and accessed by Drush) are out of sync with those loaded by WampServer. I found I had to copy my PHP settings from `phpForApache.ini` to `php.ini` in the currently loaded PHP version folder in c:/wamp/bin.2

Is Drush telling you you don't have X extension enabled, when you know you do? Run `drush core-status` to check on the path to php.ini on your own system.

### A note about the Windows zip package

I had previously used the Windows zip package to install version 6.x. As of this writing there is a package available for version 7 - scroll down to the bottom of the installation page - but not 8 (unsurprisingly since AFAIK it is heavily under development). I wonder if having previously gone through this process somehow eased this upgrade by setting up some necessary extras - probably not; I just don't know. Maybe I just become a big, fat skeptic when things work too easily on Windows.3

See also:
Installing Drush on Windows (Drupal.org)
How to Upgrade Drush to work with Drupal 8 (Manjit Singh)

---

1 Because this is Windows, it should be noted that I've only installed in the last couple of days, and have so far only used it for basic tasks such as creating databases, installing a site, clearing the cache tables. No problems so far, but that doesn't mean they won't crop up.

2 I don't recall having to copy the PHP settings over before, and this is going to be a bit sticky when I alter these settings or switch between PHP versions, but so far I haven't found a way around this.

3 The author above (Manjit Singh) seemed to have a similarly pain-free upgrade, which makes me less skeptical. :)

---
Tags: drush
---


# Question
Title: How to use Rules' "set data value" with image fields?
I would like to be able to create an entity using Rules, and then populate the image field of the entity with an image file using "set data value".

When populating text fields using "set data value" it is quite straight forward since you can either use tokens or input any text you desire. The trouble is, how do you reference the image that has been uploaded to the server? There is no appropriate token available for it.

What is the best way to achieve this?

# Answer
> 1 votes
I do something similar on my site; though the solution will vary according to where you are getting the image file from.

On my site, I first use a "Download a file from the internet" action to fetch and save the image file I want. When you are setting up this action, be sure to scroll all the way to the last fieldSet on the page - Provided variables - and make a note of the machine name there(or change it to something more memorable)

Next add a "Set a data value" action, and use the machine name from above as the Value.

\[edit\] I have just realised - while looking down my module list - that the "Download a file from the internet" Rules action is provided by a module, here is a link:- https://www.drupal.org/project/rules\_download

---
Tags: rules, media, files
---