# Question
Title: How to use [submission:values] in Email template in Webforms
I have the Webform 7.x-4.0-alpha6 version module enabled.

I have a Webform node with 20 form components. I added one email in Email Setting and I created the email template where I used the token: **\[submission:values\]**.

Then I test the webform submitting a message. The problem is that **\[submission:values\]** print out the components values in a very plain way, no break line, no semicolon to make a difference between the **title** and the **value** for each component. Something like:

```
Name Jhon
Addresss Myaddress 12
CP 19932
....

```

Having 20 component make the email completely **unreadable**

**My question is:** Is there a way (a token) to print them in a better way, at least adding a semicolon between the title and value, and making the title **bold** ? or putting the output in a table?

```
    Name: Jhon
    Addresss: Myaddress 12
    CP: 19932

```

I know that I can print out the components in a separated way using the tokens: \[webform:{component}-title\] for the title and \[webform:{component}-value\] for the value

And then I can style them. But this is time wasting since I need all components to be shown in the email template

Update: I found this module but doesn't help me: http://drupal.org/project/webform\_tokens

# Answer
I haven't such problem, but I know, how to get special values from webform.

> Webform tokens from submitted data. Includes the value and field label. Replace the "`?`" with the "*Field Key*". Append "`:nolabel`" for just the value.

So, you can use `[submission:values:?:nolabel]`, where `?` is field key of your component.

```
 Name: [submission:values:name:nolabel]
 Address: [submission:values:address:nolabel]

```

For me result is the same as for `[submission:values]`:

> Name: Kate
> Address: Moscow, Russia :)

Webform version: 7.x-4.0-alpha6 (7404).

Webform Tokens module is not needed.

## Update

If you are using HTML mail, labels are outputted via `theme_form_element_label` and look like `<label>Title</label>\n`.

You can override `webform-submission.tpl.php`. Copy this file to the theme for rendering the emails from `admin/config/system/mailsystem`.
To add `:` I suggest just to modify render array:

```
if ($format == 'html') {
  foreach ($renderable as $i => $item) {
    if (is_array($item) && !empty($item['#title'])) {
      $renderable[$i]['#title'] .= ':';
    }
  }
}

print drupal_render_children($renderable);

```

But you can output substitutions fully yourself.
> 12 votes

# Answer
Use **Send e-mail as HTML** option of webform.

This is available if you install the Mime Mail and Mail System modules, then go to `admin/config/content/webform` and set the **Format** to *HTML*.
> 1 votes

# Answer
Also note that if you're using a *Grid* component, you need to call that token with both the Field Key and then the question key. Grids are often used if you're doing a survey, for example and are asking people to rate something on a scale of 1-3, using radio buttons for each row, such as:

Sample Question:

Rank the following with 1=high, 3=lowest

```
+---------------+-----+-----+-----+
|   Breweries   |  1  |  2  |  3  |
+---------------+-----+-----+-----+
| Lighthouse    | [o] | [o] | [o] |
| Phillips      | [o] | [o] | [o] |
| Whistler      | [o] | [o] | [o] |
+---------------+-----+-----+-----+

```

To print out the value of just question 2's answer, you'd use:
Beer Question 2 value was: \[submission:values:my\_beer\_field:phillips\]
> 0 votes

---
Tags: webforms, emails
---


# Question
Title: Why do I have two menu bars in my drupal instance?
I noticed while I was building my theme, that I have 2 menu bars at the top of my screen, like so:

I don't see anywhere that would indicate there would be two.

How would I go about fixing that?

# Answer
You may have 2 toolbars enabled. One is the Drupal 7 default toolbar which in my experience most disable in favor of the the admin\_menu.

drush dis toolbar -y

or

drush dis admin\_menu -y

Or under the modules config page.
> 5 votes

# Answer
Have a look at the Administration menu issue about "Duplicate Admin menu?", which is fairly similar to what you asked.

Solution = disable core module `Toolbar`.
> 0 votes

---
Tags: toolbar
---


# Question
Title: How to login when you have a default page setup with panels?
I have been messing with panels. I set a default layout page that basically has no content and is set for all the pages at the moment. I logged out like a dummy and now when I go to website/user/login it gives me a blank page. Is there another way I can login?

Thanks!

# Answer
> If you have access to drush, you can generate a one time login link use drush \> uli. Other than that, I'm not sure other than manually restoring to a back-up - lukedekker

Awesome! That worked. I was trying something else the other day with drush that wasn't producing results.
> 0 votes

---
Tags: panels, users
---


# Question
Title: Commerce Recurring framework with customizable products
I understand that one of the field's from the recurring framework need to be part of the product and by extension a rule needs that to create a recurring entity by getting the products that have recurring field in them.

I had added the recurring field in the line items types that are of the type add to cart, so that the customer can pick what kind of recurrence they want instead of adding it to the product. These type of fields do not get picked by the Get Recurring Product action in the rules and no recurring entity is created.

Any advice on how to make this work so customers can decide the period rather than the store providing different subscription options by creating that many products?

# Answer
> 0 votes
Make a version of the product for each period:

* Toothbrush (Monthly)
* Toothbrush (Quarterly)
* Toothbrush (Bi-annual)

etc.

Then, add each of those products to the product reference. Your customer will then be able to choose which subscription they want.

---
Tags: commerce
---


# Question
Title: How to implement grouped filters filtered by roles?
Is it possible to make exposed grouped filters where some filters are only available for certain roles?

# Answer
Clone the view you already have into an additional views display, add the exposed grouped filters to that cloned views display, and then limited that additional views display to only those "certain roles".
> 0 votes

---
Tags: views
---


title: Ajax best practise for custom links

text:
# Question
Title: Ajax best practise for custom links
I was reading up on AJAX requests in Drupal 7 at http://codekarate.com/blog/drupal-7-javascript-ajax-framework-example-link

Where the AJAX framework is explained in detail, when used on custom links and potentially other HTML elements.

Now it got me wondering,

In a more "custom" point of view, I have created some (regular) hook\_menu() implementations in the past, (without any /ajax or /nojs stuff) that would just return json data.

So, basically I implemented links in my custom module that would get called via a custom jQuery file (via $.post or $.get), via a click() event or something like this, that in turn fired the hook\_menu() mentioned above.

This would then return some json data after processing the request, this returned data would get fetched by my jQuery script, and the DOM would be updated with the data that was returned by the ajax call (json, ...).

Now I am just wondering on the pro's and con's of both ways of doing things.

It figures that the first one is more "the Drupal way", and the second one is much more custom...

Since I never had any issue with using the second way of things, I am very curious to hear what you all have to say on this matter.

Thanks in advance.

Best

Guardian

# Answer
yes - you can always do custom stuff, but miss all the features of the framework.

some pros:

* works with javascript disabled (/nojs)
* you can use the form-api 1:1 (more or less ..), so forms are reusable
* you can use predefined commands (like replace or alert) and create your own
* it's all ready for jquery ui
* you can write your own and overwrite behaviors (and it's settings) from other modules
* you can use drupal translations
* with ctools it gets even more powerful, like modals, AJAX Responder etc.
* there are a lot of modules you can use (qucktabs, modal forms, masonry .. you name it ..)
* you can have all JS libraries managed
* for JSON with website content you can use views datasource module

the contra is you need to be willing to learn and adapt :D
> 5 votes

---
Tags: javascript, ajax, routes
---


# Question
Title: Editor being able to create tabs (quicktabs style) inside CKeditor
I am trying to provide a way for our content editor to create tabbed content inside the ckeditor, but I am a bit stuck.

Do you guys, have any ideas how to do that ?

**What I have already tried ?**

Quicktabs module and blocks for specific page...but this method requires too much administrator rights for the editor ( quicktabs and blocks access ).

Oleg

# Answer
A bit late to the party, but this module will do it for you. I've been using it for a while now.

https://www.drupal.org/project/ckeditor\_tabber
> 3 votes

# Answer
Just make Body field multivalue. Look for this setting:

Then it will be up to your tpl file and your theme's javascripts to style it as tabs.

---

You can also try to use Field Collection Tab formatter, it looks like what you want:

I don't know this module personally, I always did things like that on my own, but looks simple enough.
> 2 votes

---
Tags: wysiwyg, blocks
---


# Question
Title: How to override a module in sites/all/modules directory?
Is there an easy way to override a module located in **sites/all/modules** directory? Like placing it's customized version into **modules/** directory or create one under **sites/default/modules**?

# Answer
> 8 votes
Answering my own question here:

> Your installation will choose from the most specific one available (first **/sites/sitename/modules** (sitename typically might be - *default*), then **/sites/all/modules**, then **/modules**).

from Directory precedence and multi-site considerations.

# Answer
> 1 votes
To get Drupal to recognize the location of an overridden module, you may need to clear caches or rebuild the system registry.

---
Tags: files
---


# Question
Title: How do I store my client's passwords securely and make them retrievable?
I am building a site that holds information about my client's computers. One piece of information I want to store is the password for an account on each computer. I want my authenticated users to be able to log on to my site and, if they have the right permissions, be able to see these passwords (maybe by clicking a 'show password' button).

The problem with this is that I can't store just the hashed versions of these passwords in the database because obviously then there is no reliable way of getting them back to plaintext, and I don't want to store the passwords as plaintext in the database either (unless access to this part of the database is strictly password protected by my authenticated user's passwords, which I don't know how to implement), so I was wondering if anyone has any suggestions of securely providing this functionality?

Making the passwords secure and retrievable in Drupal seems mutually exclusive to me so if anyone knows of any external services that might work then I would be very interested in hearing about them as well.

I am using Drupal 7.41.

# Answer
> 1 votes
I would recommend AES. It provides strong two way encryption and if you have gov't clients, this module uses FISMA/FIPS approved algorithms. This link may also be useful. https://groups.drupal.org/node/258513

# Answer
> 2 votes
Try either the Field Encrypt module:

> Adds options to encrypt field values.
>
> The goal of this module is to create a method for encrypting field values when stored in the database.
>
> This module depends on the Encrypt module (http://drupal.org/project/encrypt) for encrypting and decrypting strings.

Or which sounds better for your use-case of "settings" the Encrypted Settings Field module:

> This module adds the "encrypted settings" field through Field API, which has the following two features:
>
> * The field can be encrypted before saving to the database
> * The field can be validated to follow INI format
>
> This module is ideal to save credential settings information, such as a "Credit Card" field to add to users' profile.

A more developer friendly form which stores the final encrypted value into the drupal database and plays nicely with Drupal 7 core Form API elements is the Encrypt Form API module:

> After installing and enabling this module, you will be able to add an '#encrypt' property to any of the following supported Form API element types:
>
> * textfield
> * textarea
> * checkboxes
> * checkbox
> * radios
> * radio
> * select
> * password
> * password\_confirm

To use this module I would recommend assuring your site is served only in SSL, then the contents of the field is encrypted on *save*, after normal form validation occurs.

# Answer
> 0 votes
**this breaks the security concept and is not recommended !**

why do you need that ?? could there be a better approach ??

you could add a field with a validation to the user entity, which the users has to input the password. so he'll type it 3 times, and it's not encrypted in the DB .. you'll need to do that yourself, fe. with help of encrypt

to not remember passwords there are password managers like lastpass.

---
Tags: users
---


# Question
Title: Disable Elysia Cron task programmatically
I have a custom module where I create several cron tasks using HOOK\_cronapi. This is done when the user visits a page and has a form to create those tasks.

I also need that the user can disable those tasks but I can't find anything in the elysia cron documentation on how to disable a cron job.

After it is created I can't disable it programmatically? (I can do it via GUI)

Thanks.

# Answer
I realize this is pretty old but if you are only concerned with one task and not a whole channel...

```
elysia_cron_set_job_disabled('mymodule_cron', true);

```

will disable a cron job. Not surprisingly,

```
elysia_cron_set_job_disabled('mymodule_cron', false);

```

enables it again.
> 1 votes

---
Tags: cron
---


# Question
Title: How to get these content types to appear in my view based on role?
I have two content types known as `Generic Credit` and `Generic Expense`. There are only three roles (Secretary, Admin, and Developer) that can create and view this type of content for administrative purposes. Additionally, these are important for a view that acts as a budget, which gathers several types of financially-related nodes. All of these content types are used for calculating a budget for teams (comprised of a coach and several students). This budget view can be viewed by the students and coaches, and it filters correctly, showing the appropriate budget for a team.

That is, unless it's pulling a Generic Credit or Generic Expense. When a student or coach without the three creating roles views the budget, these two content types don't appear. However, when a coach with the Admin or Secretary roles uses the view, they are able to see the Generic Credit/Expenses.

So far, I've tried using *Node View Permissions*, but that didn't have any affect on the views. I've also tried allowing students and coaches to create and edit the content types, but that has proved futile.

Am I missing something here with the permissions? What settings might I need to check?

# Answer
You'll need to add a restrictions in your views. There's an access restriction section there where you can set it by role. Select which roles can view it, then save. That should work. Please refer to the picture attached where to find the permission access. Also, try Content Access module to restrict content type per role.
> 2 votes

---
Tags: views, nodes, users
---


# Question
Title: Can't find migrate setting in configuration
I have installed Migrate and Migrate Drupal in admin/modules.

But after installing these module, I can't find it in configuration.

Drupal version 8.

# Answer
> 1. Using the Migrate Upgrade UI (easier)
>
> Migrate Upgrade is a UI for core upgrades from Drupal 6 and Drupal 7 to Drupal 8. It's still under heavy development, so things may break. If something fails for you, check the issue queue first! There may be a patch. If not, check with the developers in #drupal-migrate on IRC.
>
> **After installing Migrate Upgrade, visit your Drupal 8 site's /upgrade page.** When you do you will see this helpful Home screen.

Source: Executing a Drupal 6/7 to Drupal 8 upgrade

**Step 1)** Install Upgrade Migrate module

**Step 2)** Go to `yourwebsite.com/upgrade`

### Worth Noting

> If you have a Drupal 6 or 7 site you want to upgrade, install or update the Upgrade Status module to get a customized, up-to-date report on the status of your modules and themes in Drupal 8. Once you are ready, Drupal 8 core also includes the Migrate module to update existing Drupal 7 and 6 sites to Drupal 8 directly. **Migrate is marked "experimental" in Drupal 8.0.0, but will be fully supported in an upcoming release**

Source: Drupal 8.0.0 released
> 2 votes

---
Tags: 8, migrations
---


# Question
Title: Multiple Node Variants with Different Paths
I have my node content type set up using Page Manager. I have different variants for this content type that pass different arguments to my view. Is there any way to have these variants have different URLs? For example:

```
my/node/path
editors/my/node/path
retailers/my/node/path
my/node/path/anotheridentifier

```

The content will be different so I don't see an issue with SEO.

# Answer
Try creating aliases that point to the same path (your page manager page). To create aliases go to Configuration \> Search and metadata \> URL aliases
> 0 votes

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


# Question
Title: How to programmatically add default values to existing nodes of a specific content type
On a Drupal 7 site, I have a content type that is populated with existing nodes. Later, I added a new boolean field (that is required). The existing nodes now have a blank value for this field.

How do I programmatically populate these nodes with a default value?

# Answer
You may use module Views Bulk Operation. Then create views page like table and field title, your field, add field **Content: Bulk operations (Bulk operations)** with settings VIEWS BULK OPERATIONS -\> SELECTED OPERATIONS **Execute arbitrary PHP script (views\_bulk\_operations\_script\_action)**. Save, Open the page, select one node, choose **Execute arbitrary PHP script**

enter next code and execute:

```
//change entity title or what you want to do
$entity -> title = $entity->title . ' test';

//save entity
entity_save('node', $entity);

```
> 1 votes

# Answer
Just in case anyone runs into this in the future: install Field Defaults.

> Field Defaults allows batch updating of default field values to existing content. When adding a new field to an entity you can update all existing content with the default value or when editing an existing field you can choose to also update all existing content with the new value.
> 1 votes

---
Tags: nodes
---


title: How to fix a white screen of death?

text:
# Question
Title: How to fix a white screen of death?
I am dealing with a white screen of death I feel like I've pin pointed the issue, but have no way of knowing how to fix it.

This is my first time using Drupal, and my first time running into this issue. Are these errors that are in my log, related to problem? How would I go about fixing it?

Any and all help is appreciated as I have already consulted the handbook and have not found the solution to this issue by doing so.

# Answer
Open your **php.ini** (in most cases found in /etc/php5/apache2/) and modify the following options:

```
error_reporting = E_ALL
display_errors = On
display_startup_errors = On

```

Reload or restart apache after saving.

If you don't have access to this file, you can also put this in your settings file:

```
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

```

Also, set **Logging and errors** to **All** in the Drupal settings (admin/config/development/logging).
> 0 votes

# Answer
running `drush core-requirements`from your drupal site's directory more info and `tail /var/logs/[httpd | apache2]/foobar_error.log` will be your friends here.
> 1 votes

---
Tags: theming, database
---


# Question
Title: How to pass argument in ctools_modal_form_wrapper?
A very strange issue come across while using **ctools\_modal\_form\_wrapper** and **ctools-use-modal**. I have written a menu item and passed two arguments in it.

```
$items['a/b/c/d/e/%/edit/%ctools_js'] = array(
    'page callback' => 'generate_tpls_callback',
    'page arguments' => array(5,7),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'tpl_popup_create.inc'
  );

```

Now in this callback I am getting both **5th and 7th argumen**t. But when I pass it to `$form_state`, form is unable to get this 5th argument. I will explain you more with the help of code.

```
function generate_tpls_callback($cid, $ajax) {
    if ($ajax) {
        ctools_include('ajax');
        ctools_include('modal');

        $form_state = array(
            'ajax' => TRUE,
            'title' => t('Display box to change title'),
            'cid' => $cid,
        );
        $output = ctools_modal_form_wrapper('myform', $form_state);
        if (!empty($form_state['ajax_commands'])) {
            $output = $form_state['ajax_commands'];
        }
        print ajax_render($output);
        drupal_exit();
    } else {
        print_r("helloooo");
//
    }

}

```

**So, the issue is**, when I click a link say "**generate tpl**" a popup appears that contains form items. I want the above **5th argument** appears in this form. i.e. `$cid`. How can I do this. Please help.

# Answer
> 3 votes
You must use $form\_state to do it.

*$form\_state\['build\_info'\]\['args'\] = array($node);*

```
function generate_tpls_callback($cid, $ajax) {
    if ($ajax) {
        ctools_include('ajax');
        ctools_include('modal');

        $form_state = array(
            'ajax' => TRUE,
            'title' => t('Display box to change title'),
            'cid' => $cid,
        );
        $form_state['build_info']['args'] = array($myvar);  //Check form below
        $output = ctools_modal_form_wrapper('myform', $form_state);
        if (!empty($form_state['ajax_commands'])) {
            $output = $form_state['ajax_commands'];
        }
        print ajax_render($output);
        drupal_exit();
    } else {
    }

}

function myform($form, &$form_state, $myvar) {
...
}

```

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


# Question
Title: Removing div wrapper of textfield element in webform
I would like to remove div element on webform textfield. Instead of :

```
<div class="form-item webform-component webform-component-textfield" id="webform-component-vous-etes--nom">
  <input type="text" id="edit-submitted-vous-etes-nom" name="submitted[vous_etes][nom]" value="" size="60" maxlength="128" class="form-text">
</div>

```

I would like to have this :

```
<input type="text" id="edit-submitted-vous-etes-nom" name="submitted[vous_etes][nom]" value="" size="60" maxlength="128" class="form-text">

```

# Answer
> 1 votes
You would do this by overriding theme\_form\_element() in your theme, eg, something along the lines of:

```
function YOURTHEME_form_element($variables) {

  $element=&$variables['element'];

  if ( /* this is a webform textfield */ ) {

    // create the html without the div wrapper

  } else {

    // do it the standard way

  }

  return /* the html */;

}

```

A look into `includes/form.inc` will show you the full `theme_form_element()` code that you could copy into your function above where necessary.

# Answer
> 1 votes
```
function YOURTHEME_form_element($variables) {
  $element = &$variables['element'];
  if ( isset($element['#remove-div-wrap']) && $element['#remove-div-wrap'] === true ) {
    return preg_replace('/<div[^>]*>|<\/div>/is', '', theme_form_element($variables));
  } else {
    return theme_form_element($variables);
  }
}

```

Use hook\_form\_alter() to specify the affected fields:

```
function YOURTHEME_form_FORMID_alter(&$form, &$form_state, $form_id) {
  $form['mail']['#remove-div-wrap'] = true;
}

```

---
Tags: webforms
---


# Question
Title: Drupal Commons update is having troubles using drush
I have Drupal Commons distribution's based website,everything was good untill I updated the site with drush.

The problem is drush downloaded the file to `sites/all/modules` instead of `profile` folder. Now I am getting bunch of redeclare function error.

When I remove everything from `sites/all/modules` I get can't find function xxx. How will I get back the site to normal.

# Answer
> 1 votes
Drush just wasn't cut out to automatically update profiles. pm-updatecode does not do the right thing, and as you noted, even `pm-download` picks the wrong location by default.

1. To download a new version of a module that is in a profile, use `--destination` to tell Drush exactly where to put the module.
2. If you get into a situation where Drupal no longer has the right location for your modules, run the registry rebuild tool to fix things up.

# Answer
> 1 votes
The answer from Greg is correct, but I would like to add that for Drupal Commons updating modules separately isn't recommended as it can break your site. IMHO you should update all of Commons or nothing. The only exceptions would be serious security issues with modules. I guess you can use drush to update all of Commons if you want to ;-)

---
Tags: drush, updating, 7
---


title: block for the navigation

text:
# Question
Title: block for the navigation
I'm getting to grips with Drupal 7 at the moment. One thing that I'm finding frustrating at the moment (perhaps because I'm misunderstanding) is blocks.

Can you not just have a blank block give it a template and do what you want? I'm creating a sub theme off of Bartik and would like to put the main navigation into it's own block (to keep things tidy) and then just call the region this block is set but this doesn't seem to work. It seems I have to have the body text from the block included and the navigation doesn't seem to work either. I have come from developing in wordpress which has the loop, if you're in the loop you can call what you please, but this doesn't seem to be the case for Drupal?

# Answer
**Block**

1. Define region in theme information file (https://www.drupal.org/node/171205).

*Example:* `regions[main-menu] = Main Menu`
2. Call the region in template file (html.tpl.php or page.tpl.php)

*Example:* `<?php print render($page['main-menu']); ?>`
3. Clear website cache

*Procedure:* `Configurations -> Performance -> Clear all caches`
4. Now you can assign any block to the region.

*Procedure:* `Structure -> Blocks -> Here you can see 'Main Menu' region as unassigned. Assign any block to this region (example: assign menu menu block to main menu region).`

**Templating**

To know more about templating: https://www.drupal.org/documentation/theme

Since you are coming from a WordPress background, please get familiar with theme structure of Drupal and then start working on themeing.
> 0 votes

---
Tags: theming, blocks, navigation
---


title: What happened to Drupal's performance?

text:
# Question
Title: What happened to Drupal's performance?
I just installed Drupal 7 again on my cheap shared host. The installation went fine... I copied the 1098 files via FTP and installed it within 2 minutes. The standard installation (with all modules in the core) took about 5-10 seconds. After installing, the site runs well. It's a cheap hosting, so sometimes it's a little slow, but it's acceptable.

Yesterday, I've installed the new Drupal 8 (which is why I installed Drupal 7 today to compare). The first thing I noticed are the number of files: 12327. I understand modules like Views are included in the core now, but an increase of the number of files of over 10 times seems a little odd to me.Is there another reason for this?

Once I copied all files, I've tried to install Drupal 8. What a nightmare. The installation page takes up to 20 seconds to load. When I want to start the installation, I'm getting a notice OPcache is not enabled in PHP. Is this the reason for the slowness? Is there an alternative available?

Continuing the installation, I'm getting random errors. Searching for them on Google doesn't help getting me more information. Something about a fixed bug months ago, that's all I could find. I had to restart 3 times before the installation succeeded.

The biggest issue is the performance. Installing all these modules during the default installation took about 5-10 seconds in Drupal 7. It took about 20-30 minutes in Drupal 8. Okay, some more modules are included now, but this seems very odd. As I had to retry 3 times, it took me about 2 hours just to install Drupal 8. After installation, it was unusable slow, so I had to remove the whole installation.

I'm wondering if someone knows more about this issue. Does Drupal 8 require like 20 times more resources than Drupal 7 to run properly? Or is all of this because of the missing OPcache? Am I the only one with this issue?

Any advice would be welcome as I'd like to try the new features. Drupal 7 runs perfect on my cheap hosting, but Drupal 8 is a real nightmare.

I'm not sure what other technical information might to relevant to find/resolve this issue.

# Answer
D8 requires more resources and yes, you should have hosting with opcache enabled, which is included by default in PHP 5.5.

Drupal 8 has so many files because it includes symfony and other projects and everything is a class.

FTP is a very bad idea for D8 and web in general in 2015. Look for a better way to do web hosting.

That said, it should not take *that* long. I suggest you open a bug report and provide as many details as you can about your specific PHP version, hoster, the errors that you had, ..
> 9 votes

---
Tags: 8, caching, performance
---


title: Translate module strings

text:
# Question
Title: Translate module strings
In a custom D8 theme, we have some strings in twig using |t filter and in php using $this-t() funtion.

example :

```
{{'More Headlines'|t}}

```

```
$this->t('replies')

```

These strings are not listed in /admin/config/regional/translate. What's the right way to translate it via the administration interface like it was possible with D7?

# Answer
> 4 votes
You just need to first visit the page rendering the string you want to translate while using any other language.

Drupal only adds this string to the database once it has been rendered once, and you will be able to see it in the `/admin/config/regional/translate` page.

---
Tags: 8, i18n-l10n
---


# Question
Title: How can the divs added by default by Views be removed?
In Views module, if I don't use any classes, even not the default, it still insists of wrapping the field contents into **divs**. I have had to use `views-view-fields--VIEW-ID.tpl.php` to theme the content, when it would had been very easy to tell Drupal not to warp with divs. Surely I am doing something wrong in the UI of Views, but I cannot identify what: in each field, the *Style Settings* has every checkbox unchecked, even the *"Add default classes"* checkbox.

# Answer
> 2 votes
On the contrary, you NEED to select the boxes for field, label and wrapper, and select **None** in the drop down menu. This will get rid of the `<div>`.

The **Add default classes** has nothing to do with the HTML elements - only with the css classes it adds to the tag.

Additionally you can deselect **Provide default field wrappers** under Format \> Settings

**EDIT**: So, testing confirms that there are NO divs for fields anymore if you uncheck **Provide default field wrappers**. See image. Why modify a tpl file if you can do this with the interface? The only divs you see in the image are the ones that separate rows in the Unformatted list output. "See, mom, no divs!"

# Answer
> 0 votes
Here is default `views-view-fields--VIEW-ID.tpl.php` template:

```
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

```

You can remove all wrappers by doing this:

```
<?php foreach ($fields as $field): ?>
  <?php print $field->label_html; ?>
  <?php print $field->content; ?>
<?php endforeach; ?>

```

Or even like this:

```
<?php print $fields['FIELD_NAME']->content; ?>

```

Note that after those changes you won't have possibility to change wrappers through Views UI.

# Answer
> 0 votes
You're doing nothing wrong. Altering the view templates is the only way to get rid of the divs.

---
Tags: theming, views
---


# Question
Title: Most user friendly way to organise this content?
We're trying to work out how best to organise this content: https://international.permaculture.org.uk/for-organisations

It should be one column layout but with text and image aligned next to each other which will then be responsive (i.e. image moves to below paragraph associated with it)

It was suggested that the responsiveness could be detailed in within the text editor source for each pane, by giving the text and image separate div tags and assigning them some css, but I think the administrators who are going to use these sites would not feel happy with that approach.

I am wondering if using Nodequeue module is a good idea? Or if there is another way? Content order needs to be felxible so I don't think using a view is best way.

# Answer
> 0 votes
I'd recommend using the Bootstrap 3 theme/module it is very easy to install and use, and has built-in responsiveness to mobile vs laptop screens, which automatically moves your images below text, changes your menu to the mobile menu button, and other nifty features. You can copy its subtheme and make it into your own custom theme and there change many of the vanilla styles as well, so its very customizable.

---
Tags: theming, nodes
---


# Question
Title: In Views, how can I show users with one role before all other users?
I have several views of users and I want to show all users with a certain role (example, "show\_me\_first") before all other users in all of these views.

I thought this would be easy, but apparently there is no "User: Role" as a sort criteria (I'm using Views 3.5 on Drupal 7.15). I can filter by role, but I don't want to filter; I just want to show users with the role "show\_me\_first" before all other users.

How can I implement this? Minimal view customization is best because I will have to repeat this for a lot of views. If there is a way to do it without using roles, I would be open to that as well.

# Answer
A common use case is to show content from "premium" users before content from other users. This is more binary than a true weighting. If this is your use case, consider using Views' attachments.

1. Create your view. Add relationship for Content: Author.
2. In main display, set filter by role to indicate that the author is not a "premium" user (e.g. User: Roles / none of / "premium", "other premium role", etc.)
3. Add new views display of type "attachment"
4. In attachment display, alter filter by role to include the roles excluded in main display
5. In attachment settings, select your main display for "Attach to" setting; Select "Before" for Attachment position
> 1 votes

# Answer
It looks like it's not possible with one View (Sort By User Role, Sort By User Role: A New Idea?) which does kinda suck.

One option is to make two Views, one that filters on the user role you want at the top, and then one that filters OUT the user role.

Another option (this one would probably be easier to maintain) would be to create a field on the user accounts called Weight (you could hide it with Field Permissions), and then use Rules to populate that field with a high number for your chosen role when a user is created or edited, then you should be able to sort on that field. If you do this though don't forget to create a second rule to remove/change the value in that field if the role is removed form a user.

tl;dr

* Create Weight field on users
* When a user is created, fire off a rule that looks for a particular user role
* If it finds it, put a number in the Weight field
* Sort your view on the Weight field
* Make an "opposite" rule to remove the Weight value on Role removal.
* Profit
> 2 votes

# Answer
If memory serves me correctly, you use a Flags for other things along these same lines. So, if so, how about a global 'show me first' flag that you/your admins can set on a user? Kinda like your own custom sticky bit. A quick look here only allows one to sort on the flagged time, but you could use this flag to set a hidden from the user field that you could sort on.
> 1 votes

---
Tags: views
---


title: Creating new entity with rules

text:
# Question
Title: Creating new entity with rules
I want rules to create a new entity on a timed schedule in the middle of the night, when no when is on the . My question is what do I use for "The author of the node"?

# Answer
This depends on the purpose of the content. Provided that it is just administrative content, you could just use the admin user (UID = 1). If the content needs to relate to another user, then you should use them as the author.
> 0 votes

---
Tags: rules
---


# Question
Title: How can I restrict changes to certain fields in a view for a user?
I have a view with a few fields and a few filters. I was wondering if there is a way to restrict a certain role from being able to change the fields/filters but only change one filter?

I know I can restrict access to the whole views from certain roles that's not what i'm trying to accomplish.

Example:

Edit: Sorry, should have been more clear.

I have a client who has a service being featured on the front page of the site.

I have a view which shows fields from the featured service content type.

I need the owner of the site to be able to filter which piece of content to be show on the front of the site with the filter that should be editable but not mess up the view by accidentally changing other fields or filters. I do not need the filter exposed to visitors.

# Answer
You can expose only the `Title` filter to the user. They will be able to see all of the content, but only specify the exposed filter.

You can expose a filter while editing it by checking the box that says "Expose this filter to visitors, to allow them to change it".
> 0 votes

---
Tags: views, users
---


# Question
Title: Establish relationship between two text fields
I am stuck in a strange issue. I have two content types `twilio` and call `recordings`. Both content types have `caller phone number` in common

1. Recording
2. Twilio

Now I would like to generate a report using `views` which can select field between two content types based on `phone number`.

In non Drupal terms I want **inner join** based on two **text fields.**

How can I achieve this?

# Answer
Both content types have to share a field, in the same way a both the database tables used in a `INNER JOIN` have to share a common field for the join to work.

In Drupal, this is easy as you can reuse fields between your content types and in this wway joining the content types will be super simple with Views.

**Current setup:**

> Recording: field\_called\_phone, field\_caller\_phone
>
> Twilio: field\_phone\_number

**Suggested setup:**

> Recording: field\_called\_phone, ***field\_phone\_number***
>
> Twilio: ***field\_phone\_number***
> 1 votes

---
Tags: views
---


# Question
Title: nodeaccess prevent some roles to view views contents even if they allowed to access
I'm using nodeaccess module to secure some published contents from being seen by normal users or anonymous.

I have a view allowed only to admin and moderator roles to access, but when nodeaccess module is enabled moderator role couldn't see the view contents. the moderator have permissions to view and edit the content of this content type.

I tried to change the view permission access to "**view publish content**", it doesn't work until I disable nodeaccess.

So I want understand I what is them problem, and how can allow moderator user to view the view contents? Or at least if nodeaccess is not recommended in my usecase what I should do instead?

# Answer
> 0 votes
I found this module node\_view\_permissions, it did what I want in my use case, so I removed nodeaccess.

> Node view permissions module enables permissions "View own content" and "View any content" for each content type on permissions page as it was on Drupal 6. It's as simple as that.
>
> It's implemented in a non-conflict way, so you can use it with any other permissions related module.

---
Tags: users
---


# Question
Title: How to add canonical links on ALL URL's?
What is the best way to get canonical links on ALL URL's in D7?

I see nodes already have relative canonicals but I have a site with a lot of non node URL's that also need canonicals.

I added code to my `html.tpl.php` to add a canonical on any page but now I get double ups on node based pages.

Thanks for anyone taking a look at this.

**UPDATE:**
I used a `theme_html_head_alter()` hook to remove the node canonicals.
Then I added new canonicals into the `html.tpl.php` so every page has them and there is only one on the node pages.

# Answer
I used a theme\_html\_head\_alter() hook to remove the node canonicals. Then I added new canonicals into the html.tpl.php so every page has them and there is only one on the node pages.
> 3 votes

# Answer
As mentioned elsewhere, global redirect is a good option. But even Metatag is a good module. It not only handles the canonical urls but also meta keywords, description, Copyright data and many more important Meta data including OG. So, you can also have a check on this module. http://drupal.org/project/metatag and a tutorial on how to get the canonical url to work on this link: http://amitavroy.com/justread/content/articles/canonical-links-and-drupal-7

The one thing with meta tag module is that by default it will print relative canonical urls whereas I have seen major sites like smashingmagazine, engadget etc uses absolute. So, if you want that to happen then the second url is the key.
> 7 votes

# Answer
Try the Global Redirect module. Here is a quote about it (from the module's project page):

> ... a simple module which:
>
> 1. Checks the current URL for an alias and does a 301 redirect to it if it is not being used.
> 2. Checks the current URL for a trailing slash, removes it if present and repeats check 1 with the new request.
> 3. Checks if the current URL is the same as the site\_frontpage and redirects to the frontpage if there is a match.
> 4. Checks if the Clean URLs feature is enabled and then checks the current URL is being accessed using the clean method rather than the 'unclean' method.
> 5. Checks access to the URL. If the user does not have access to the path, then no redirects are done. This helps avoid exposing private aliased node's.
> 6. Make sure the case of the URL being accessed is the same as the one set by the author/administrator. For example, if you set the alias "articles/cake-making" to node/123, then the user can access the alias with any combination of case.
> 7. Most of the above options are configurable in the settings page. In Drupal 5 you can access this after enabling the globalredirect\_admin module. In Drupal 6, the settings page is bundled into the module.
> 0 votes

# Answer
Download the Metatag module, go to its settings and

1. Click "edit" next to the **Global** settings
2. Go the **Canonical URL** field (under the *Advanced* tab)
3. Fill out the following: `http://yourdomain.com[current-page:url:relative]`

This will come in handy when you use multiple domains for one website. It will avoid duplicate content flags.
> 0 votes

---
Tags: uri, 7
---


# Question
Title: Use order number instead of order id in Drupal Commerce checkout URLs
I'm trying to make the `order_number` be a randomly generated alphanumeric string and use it as the only customer facing unique ID that the customer ever sees relating to their order. However, the auto-incremented `order_id` still appears in all the checkout and order URLs.

Looking for examples of if this is being done in the wild on https://drupalcommerce.org/showcase, I found Lush, whose `order_id` increments by multiples of 5 in the checkout and order URLs. It's hard to tell if this is still the `order_id` or the `order_number` being displayed in the URL.

A popular solution is to change the `order_number` into an alphanumeric pattern on hook\_commerce\_order\_presave(), like what’s mentioned here: https://drupalcommerce.org/discussions/8900/how-change-order-number-numerical-default-alpanumeric-pattern. The problem with that is the order number gets a new format, but the order id itself remains the auto-incremented integer and is still displayed in the checkout and order URLs.

Most examples I found recommend altering the `commerce_order` table and setting the starting order id to 1000 and letting it increment by 1 from there. Like what’s mentioned here: https://drupalcommerce.org/questions/3172/how-can-i-change-starting-order-number. This is a somewhat better solution, but still not as customizable as I would like because the `order_id` is still incrementing by 1.

The most promising solution seems to be encrypting and decrypting the `order_id` in the URL using `hook_url_inbound_alter()` and `hook_url_outbound_alter()`, like what’s mentioned here: Drupal Commerce | Hide or set an alias to the order number in the checkout path. This however requires the php mcrypt library, which I will not be able to use on my production server.

Any help, examples, or advice would be greatly appreciated!

# Answer
> 1 votes
Thanks @bob!

*Just a bit of background*: I'm dealing with a 3rd party order fulfillment company who provides me with an API to generate orders in their Magento system after orders are created in my Drupal Commerce system. The 3rd party passes back the order number from the Magento API, which I store as `$order->field_vendor_order_number` in Drupal Commerce. Later I actually replace the Drupal Commerce `$order->order_number` with the custom field I created to temporarily hold the 3rd party's order number. I do this after successfully processing the customer's payment, so unfortunately all the checkout pages leading up to the "thank you" page still have the internal commerce `order_id` in the url because the order hasn't been created in the 3rd party's system yet, and therefore I don't have the proper order number that I want to show the customer yet.

Here are the rules, actions, and callbacks that send an order to the 3rd party and save the order number they respond with as the new Drupal Commerce `order_number`:

```
/**
 * Implements hook_default_rules_configuration().
 */
function example_store_default_rules_configuration() {
  $rules = array();

  /**
   * Add a reaction rule to send the order to 3rd party for fulfillment upon checkout completion.
   */
  $rule = rules_reaction_rule();

  $rule->label = t('Send Order for Fulfillment');
  $rule->tags = array('Example Store');
  $rule->active = TRUE;

  $rule
    ->event('commerce_checkout_complete')
    ->action('example_store_send_order_for_fulfillment', array(
      'commerce_order:select' => 'commerce-order',
    ));

  $rule->weight = 1;

  $rules['example_store_send_order_for_fulfillment_rule'] = $rule;

  /**
   * Add a reaction rule to update the order number to the one assigned by 3rd party fulfillment upon checkout completion.
   */
  $rule = rules_reaction_rule();

  $rule->label = t('Assign Fulfillment Order Number');
  $rule->tags = array('Example Store');
  $rule->active = TRUE;

  $rule
    ->event('commerce_checkout_complete')
    ->action('example_store_assign_fulfillment_order_number', array(
      'commerce_order:select' => 'commerce-order',
    ));

  $rule->weight = 2;

  $rules['example_store_assign_fulfillment_order_number_rule'] = $rule;

  return $rules;
}

/**
 * Implements hook_rules_action_info().
 */
function example_store_rules_action_info() {
  $actions = array();

  $actions['example_store_send_order_for_fulfillment'] = array(
    'label' => t('Send Order for Fulfillment'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order to send for fulfillment'),
      ),
    ),
    'group' => t('Example Store'),
    'callbacks' => array(
      'execute' => 'example_store_send_order_for_fulfillment_callback',
    ),
  );

  $actions['example_store_assign_fulfillment_order_number'] = array(
    'label' => t('Assign Fulfillment Order Number'),
    'parameter' => array(
      'commerce_order' => array(
        'type' => 'commerce_order',
        'label' => t('Order to assign a new fulfillment order number'),
      ),
    ),
    'group' => t('Example Store'),
    'callbacks' => array(
      'execute' => 'example_store_assign_fulfillment_order_number_callback',
    ),
  );

  return $actions;
}

/**
 * Callback for rules action to send the order for fulfillment to 3rd party API and process the response
 * Save the 3rd party order number into a custom field on the order entity
 */
function example_store_send_order_for_fulfillment_callback($order) {
  include_once DRUPAL_ROOT . '/services/ExampleStoreService.php';
  $objExampleStoreService = new ExampleStoreService();
  $arrResponse = $objExampleStoreService->SendOrder($order);

  if ($arrResponse['status'] === 'success') {
    $order->field_vendor_order_number['und'][0]['value'] = $arrResponse['order_number'];
    $order->log = 'Order Number from 3rd party is: '.$order->field_vendor_order_number['und'][0]['value'];
    $order->revision = TRUE;
    commerce_order_save($order);
  }
}

/**
 * Callback for rules action to assign the new order number received from 3rd party fulfillment
 * Take the order number stored in the custom field and actually save it as the order entity's order_number
 */
function example_store_assign_fulfillment_order_number_callback($order) {
  if (isset($order->field_vendor_order_number['und'][0]['value']) && !empty($order->field_vendor_order_number['und'][0]['value'])) {
    $order->order_number = $order->field_vendor_order_number['und'][0]['value'];
    $order->log = 'Order Number '.$order->order_number.' saved.';
    $order->revision = TRUE;
    commerce_order_save($order);
  }
}

```

However instead of going to the default "Checkout Complete" page, I created a rule that reacts to the checkout\_complete event by redirecting to "store/order/\[commerce-order:order-number\]". **Notice** it has a weight of 10, to ensure it's the last thing I want to do when reacting to the `checkout_complete` event.

```
{ "rules_redirect_to_custom_checkout_complete_page" : {
    "LABEL" : "Redirect to custom checkout complete page",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "10",
    "TAGS" : [ "Commerce Checkout", "Example Store" ],
    "REQUIRES" : [ "php", "rules", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "DO" : [
      { "redirect" : { "url" : "store\/order\/[commerce-order:order-number]\/" } }
    ]
  }
}

```

I added a `hook_menu` entry for this, which accepts the order\_number instead of the internal commerce order\_id as an url argument:

```
/**
 * Implements hook_menu().
 */
function example_store_menu() {

  $items['store/order/%'] = array(
    'page callback'   => '_example_store_order_view',
    'page arguments'  => array(2),
    'access callback' => TRUE,
    'type'            => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Custom page callback for store/order/%
 * @param  string $order_number - order number from 3rd party fulfillment api
 * @return array - order as renderable array
 */
function _example_store_order_view($order_number) {
  if (!empty($order_number)) {
    $order = commerce_order_load_by_number($order_number);
  }

  if (!empty($order)) {
    $entity_view = entity_view('commerce_order', array($order->order_id => $order), 'customer', NULL, TRUE);
    return theme('example_store_order_complete_thank_you', array('entity_view' => $entity_view));
  }
  else {
    drupal_set_message(t("No order was found for order number ". $order_number . ". Please check your order number to make sure it is correct."), 'error');
    drupal_goto('store');
  }
}

```

And a custom `hook_theme` entry to handle the template for this custom "Order Complete Thank You" page, which mainly just displays the rendered order entity. If you have any Google Analytics e-commerce tracking code, this is the template in which you'd want to place those scripts. I'm not displaying it in this stripped down example, but I rigged mine up to only render those scripts on the first visit of this page, that was if the customer refreshes the thank you page, Google Analytics won't see duplicate tracking.

```
/**
 * Implements hook_theme().
 */
function example_store_theme($existing, $type, $theme, $path) {
  $module_path = drupal_get_path('module', 'example_store');
  return array(
    'example_store_order_complete_thank_you' => array(
      'variables' => array(
        'entity_view' => NULL,
      ),
      'template' => 'example-store-order-complete-thank-you',
      'path' => $module_path.'/templates',
    ),
  );
}

```

Contents of `example-store-order-complete-thank-you.tpl.php`:

```
//Render the order entity
print render($entity_view);

```

# Answer
> 0 votes
i am not sure if you already found an answer to your question, but here's a solution i came up with, after experimenting also with the `hook_url_inbound_alter()` and `hook_url_outbound_alter()` suggestion, which by the way doesn't work if additional querystring parameters are added to the url (in my case: ?currency=USD).

So i followed the popular alternative as you mentioned above and wrote this hook on commerce\_order\_presave :

```
function hook_commerce_order_presave($order) {
    if (!isset($order->order_id) && $order->status == 'cart') {
        // Presave on first add to cart event when order_id has not yet been assigned

        $last_id = db_query('SELECT MAX(order_id) FROM {commerce_order}')->fetchField();
        $auto_increment = $last_id + 7;
        $sql = "ALTER TABLE {commerce_order} AUTO_INCREMENT = $auto_increment";
        db_query($sql);
    } else {
       $order->order_number = sprintf('%08d', $order->order_id);
    }
}

```

As visible in this screenshot, the first presave() fires on first add to cart without a filled in order\_id. This was what i was looking for to manipulate the AUTO\_INCREMENT value in the commerce\_order table. In this example increased with 7, but you could also increase it with a random value.

Additionally, i setted the order\_number to the same order\_id value, yet zero prefixed to 8 digits.

Hope this brings you closer to your preferred solution.

---
Tags: commerce
---


# Question
Title: Biblio module: importing ris files, titles not importing even though mapped correctly
I have ris files of citations to upload, and despite having titles mapped correctly at admin/config/content/biblio/iomap/edit/ris -- T1 goes to Title, I get nothing but "untitled" nodes. I am using version 7.x-1.0-rc7. Some other data seems to populate appropriately, but looking at logs, many things aren't, so it's more than just titles. I have a large number of errors for a number of fields along the lines of:

```
Notice: Undefined property: stdClass::$title in _biblio_ris_parse_line() (line 357 of C:\wamp\www\mysite\sites\all\modules\biblio\modules\RIS\biblio_ris.module).

```

Thinking there might be something wrong with the data, I created my own simple ris file and tried an example file that I found online. I had the same problems with all of them.

I tried the dev version and have the same problem.

Any help would be appreciated.

# Answer
> 0 votes
after finding this comment, I changed two lines in biblio\_ris.module:

339 from

```
$node->biblio_pages .= ($tag == "SP") ? $data : " - " . $data;

```

to

```
$node->biblio_pages = ($tag == "SP") ? $data : " - " . $data;

```

and 357, from:

```
$node->$field .= $data;

```

to

```
$node->$field = $data;

```

It works.

---
Tags: importing-exporting
---


# Question
Title: Drupal site returning 404 error for all pages besides the main page
I have two completely independent Drupal installations on the same server. Both have https enabled in the settings file, and the Apache configuration was literally copied from one file to the other. However, one of them works under HTTPS and the other does not. The broken site will open the front page successfully, but, for example, https://www.example.com/user will return a 404. https://www.example.com/index.php?q=user works fine.

I opened the apache config of the WORKING site, and changed the DocumentRoot to the directory of the BROKEN site, and tried the site using the working URL, and I see the broken site...and it IS STILL broken. This leads me to believe that it is not Apache, but something in the Drupal installation or configuration which is misbehaving.

Both installations have an .htaccess file in the base directory, and in sites/default/files, and the files are identical.

The apache error logs for both sites have the same errors:

server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)

and

server certificate does NOT include an ID which matches the server name

Any advice on where to look next?

# Answer
> 0 votes
I copied and pasted the `<VirtualHost *:443>` section several times...and every time I changed the ServerName and ServerAlias...but didn't change the `<Directory /var/www/example.com>`

I hang my head in shame and embarrassment.

---
Tags: 7
---


title: OAuth2+ OpenID Connect SSO

text:
# Question
Title: OAuth2+ OpenID Connect SSO
I am trying to implement the OpenID Connect SSO as outlined in Nik Vahalik’s YouTube video and in Patrick Dawkins’ Tutorial. I have gone step by step through their implementation instructions as well on the documentation page (https://www.drupal.org/node/2274367).

I have the OAuth server running on one Drupal Instance. I have the client login setup on a different Drupal Instance. I have the sso.php located in the root of each Drupal instance.

When I click “Login with Generic” on the client site, I get an error that says “Not Found The requested URL /oauth2/authorize was not found on this server.” The URL bar shows this as its attempted destination: https://devcondrupal.genieve.com/oauth2/authorize?client\_id=devdrupalclient&response\_type=code&scope=openid%20email%20profile&redirect\_uri=https%3A//devdrupal.genieve.com/%3Fq%3Dopenid-connect/generic&state=7a4e2dc4a66e3aa3b4531b5d523f6371

I am using self-signed SSL certificates on both the OAuth Server site and on the Client site.

I don’t know where to begin troubleshooting the issue as this is my first experience with OAuth / OpenID and there is not much information out there on the web (Drupal-wise).

Thanks for your help.

# Answer
It turns out that "Clean URLs" need to be turned on for OpenID... I added "AllowOverride All" to the section under VirtualHost in my Apache config file. This allowed me to turn on Clean URLs and the error is now gone.
> 3 votes

---
Tags: authentication-authorization
---


title: Changing column position in rows

text:
# Question
Title: Changing column position in rows
I've this layout:

```
<div class="row1">
    <div class="col-sm-4 col-md-4" id="col1"></div>
    <div class="col-sm-4 col-md-4" id="col2"></div>
    <div class="col-sm-4 col-md-4" id="col3"></div>
</div>
<div class="row2">
    <div class="col-md-12 col-xs-12" id="col4"></div>
</div>

```

This is perfect on large-small screen. But not adapt for what i want to displayed on mobile. Displayed:

col1 col2 **col3**

```
 col4

```

How can i get this: col3 and col4 reodered on mobile. Like this:

col1 col2 **col4**

```
 col3

```

So col4 change from row2 -\> row1, col3. And cal3 get from row1 -\> row2, col4. Just on mobile. **Note: This is to be applied just on *mobile/small screen*. For the display is fine for midle and large screen.**

# Answer
If you're able to use a flex container for your divs all in the same div, you might try using the order property in a media query for smaller screens. It lets you select the order of elements. I've done a fiddle here.

Here's the CSS I used.

```
.row1 {
  display: flex;
  flex-wrap: wrap;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
}
@media (max-width: 767px) {
  #col1 {order: 1;}
  #col2 {order: 2;}
  #col3 {order: 4;}
  #col4 {order: 3;}
}

```
> 1 votes

# Answer
You won't be able to do this using Bootstrap grid classes alone. The easiest way to do it without touching JavaScript would be to bring all the columns into the same parent container and add a copy of the third column that you toggle between:

```
<div class="row1">
    <div class="col-xs-4 col-sm-4" id="col1">#1</div>
    <div class="col-xs-4 col-sm-4" id="col2">#2</div>
    <div class="hidden-xs col-sm-4" id="col3a">#3</div>
    <div class="col-xs-4 col-sm-12" id="col4">#4</div>
    <div class="hidden visible-xs-block col-xs-12" id="col3b">#3</div>
</div>

```

You could probably do it with the fourth column instead, if the content makes it easier.
> 0 votes

---
Tags: display-suite, theming
---


title: Translate not working for some strings

text:
# Question
Title: Translate not working for some strings
I am using Drupal commons. I am using I18n and other related modules for my website as it is created in English but is being used in French also. I am using translations provided. My issue is that I have string translations but for some strings, text is not being translated, although the translations are available in the drupal.

**UPDATE** After going through code, I found that this "Request Message" field is not a normal form field, but it is being rendered using

```
     field_attach_form('og_membership', $og_membership, $form['membership_fields'], $form_state);

```

The issue is with this "**field\_attach\_form()**". Do ANYONE have any idea what can be done for this??

# Answer
> 5 votes
Although I know this solution is not best and structural method and is better solve this issue but sometimes we just need a solution and want save the time(maybe it be some issue with commons distributes.
Sometimes I do this trick in some projects

if you want translate all `keystring` in every where use

```
 $('body').html( $('body').html().replace(/keystring /g, "TranslateString"));

```

and also if you want only some specified(with specified class and page class) string use

```
$('.checkout-review .field-name-phone-mobile .field-label').html($('.checkout-review .field-name-phone-mobile .field-label').html().replace(/keystring /g, "TranslateString"));

```

You just need put one of them in JS file.

# Answer
> 0 votes
Drupal's language translation can be hit or miss sometimes. Often times its silly little pieces like the part that you mentioned that dont get translated while 95% of the rest of the page translate without issues. Google to the rescue!! I recommend the Gtranslate module to get you started and of course you can place the google translate api directly into a tpl or module file to get the full monty!!

---
Tags: i18n-l10n
---


# Question
Title: Allow users to edit own unpublished content
I would like to provide users with *role-A* and *role-B* the ability to edit their own published and unpublished content. I've installed the Content Access Module and seems impossible to make this without coding. Does anyone know how to solve with code?

# Answer
> 1 votes
I am not sure about your exact requirement. If you want to list all contents created by current user with an edit link, my suggestion to make try with **views**.

1. Give **Edit Own Content** permission to your **needed roles** for all content types in **Home » Administration » People » Permissions**.
2. Create a view with **content of all**.
3. Add title in fields (or the fields you want).
4. If you want to give an **edit link** , add **Content:Edit Link**.
5. In views contextual filter add **Content:Author uid = User ID from logged in user** (Refer here).
6. Change format to **Table** (Only title and edit link is there this gives a nice formatting).

Hope this will help you.

# Answer
> 0 votes
You can try this in your own module:

```
function MODULE_permission() {
    return array(
        'edit own unpublished content' => array(
            'title' => t('Edit own unpublished content'),
            'description' => t('Allow user to edit own unpublished content.'),
        ),
    );
}

function MODULE_node_access($node, $op, $account) {
    if (user_access("edit own unpublished content") && $op == "update" && $node->status == 0 && $node->uid == $account->uid) {
        return NODE_ACCESS_ALLOW;
    }
}

```

It will add a permission that is applicable to all nodes. If you want to set it for a specific bundle only you will have to expand on it a bit.

---
Tags: nodes, users
---


# Question
Title: How to increase the speed of SQL Views queries?
I have a View with two relationships, and a few displayed fields. It has a COUNT (use aggregation). The database contains just about 10.000 rows. It takes 4 seconds to complete. A similar query to the very same tables takes 0.002 seconds, i.e., 2000 times faster! It is supposed that the Views module is smart enough not to get involved in a `burocracy` of tables that will take forever to load the data, but it happens. How can I solve it?

I put the example. Essentialy, they do the same (I need to take a little extra info, but essentialy to get the list of products and number of products in a category, the SQL is working. See the SQL query in one case, and in the other). And I was just very carefully adding the two relationships and the fields, so either I did something very wrong or Views SQL UI needs a very lot of improvement.

Quite fast query:

```
SELECT SQL_NO_CACHE field_familia_tid, COUNT( DISTINCT node.nid ) AS total
FROM field_data_field_oem_ubicacion AS ubi, field_data_field_oem_ref AS oem_ref, field_data_field_familia AS familia, field_data_field_marca AS marca, node
WHERE ubi.field_oem_ubicacion_value = oem_ref.entity_id
AND oem_ref.entity_id = familia.entity_id
AND oem_ref.entity_id = marca.entity_id
AND field_marca_tid =69440
AND node.nid = ubi.entity_id
GROUP BY field_familia_tid

```

A similar query, done carefully with the Views UI. Extremely slow, 1000 times slower:

```
SELECT taxonomy_term_data_field_data_field_familia.tid AS taxonomy_term_data_field_data_field_familia_tid, COUNT(DISTINCT field_oem_ubicacion_field_collection_item.nid) AS field_oem_ubicacion_field_collection_item_nid
FROM
{field_collection_item} field_collection_item
LEFT JOIN {field_data_field_familia} field_data_field_familia ON field_collection_item.item_id = field_data_field_familia.entity_id AND (field_data_field_familia.entity_type = 'field_collection_item' AND field_data_field_familia.deleted = '0')
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_field_data_field_familia ON field_data_field_familia.field_familia_tid = taxonomy_term_data_field_data_field_familia.tid
LEFT JOIN {field_data_field_marca} field_data_field_marca ON field_collection_item.item_id = field_data_field_marca.entity_id AND (field_data_field_marca.entity_type = 'field_collection_item' AND field_data_field_marca.deleted = '0')
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_field_data_field_marca ON field_data_field_marca.field_marca_tid = taxonomy_term_data_field_data_field_marca.tid
LEFT JOIN {field_data_field_oem_ubicacion} field_data_field_oem_ubicacion ON field_collection_item.item_id = field_data_field_oem_ubicacion.field_oem_ubicacion_value
LEFT JOIN {node} field_oem_ubicacion_field_collection_item ON field_data_field_oem_ubicacion.entity_id = field_oem_ubicacion_field_collection_item.nid
WHERE (( (field_data_field_marca.field_marca_tid = '69440') ))
GROUP BY taxonomy_term_data_field_data_field_familia_tid

```

**Note:** Afterr careful inspection of SQL and also from suggestion by user tenken, I replaced the LEFT JOIN by WHERE-AND in the SQL. The result was almost identical, and fast, so now the question is: why does Drupal uses by default the LEFT JOIN, and where can I change it (if possible, not programmaticaly, in order to have the logic inside the View).

# Answer
The primary reason Views uses `LEFT JOIN` is to account for empty fields. `INNER JOIN` implicitly assumes there are field values. Depending on what source you read, `INNER JOIN` can be preferable over the `WHERE-AND` style because it will limit the amount of data the `WHERE` operates on.

Your optimized query makes a few assumptions on the data.

1. Your fields are only on the field collections. It is possible for the same field to be on multiple entity types, hence the `f.entity_type = ...` portion of the query.
2. Your fields still exist. The `deleted` column is used during garbage collection during cron runs when you delete a field (see `field_cron` and `field_purge_batch`).
3. It looks like you have optimized some of the other joins away, by knowing what data you don't need.

A better benchmark would be to convert your query to use `INNER JOIN`. You can do this with a `hook_views_query_alter(&$view, &$query)`. I don't have a working example of this handy, but `dpm()` the `$query` object, and you will see the property that has the joins in it. You can change the join type, and you can potentially remove unnecessary joins.
> 4 votes

# Answer
Take the query from the Views admin and from the mysql command line, or phpmyadmin add the `EXPLAIN` keyword in front of it. Assure it's using `indexes` on query criteria and that the query is optimized.

If it's not a fully optimized query then simply add an index to your SQL schema as needed until it's as optimized as it can be.

You can either add the index directly to tables through phpmyadmin, or create a module to index the necessary db fields (and then drop indexes if the module is disabled).

Drupal ships with a db that is not fully optimizted for any query you could generate with views. Module creators make general assumptions in the table they make to provide primary keys for example -- but they don't index every column of their schemas as taht would be wasteful. How you use Fields on your site is different from how I would use fields on my sites ... etc.

1 module that may help you index your Drupal fields (after evaluating the `EXPLAIN` output is) Field Index:

> Field modules don't always add indexes for its columns (value column of text field for example), this leads to poor performance in views when we would like sort or filter views using the unindexed columns. We can check the query executed by views and add custom indexes manually, but it's not easy to deploy.
>
> With field\_index module, we can create custom indexes for fields. The indexes are exportable.
> 5 votes

# Answer
In fact, it is the Views config which is wrongly done. To get the same results than the query SQL, use «Require this relationship» in the relations and you are done.
> 1 votes

---
Tags: views
---


# Question
Title: How/where is the marker layer added to the Google Map with the Gmap Module?
So,

I'm interested in trying to "export" a collection of markers from a Google Map generated by the Gmap module. Specifically, I'm looking for how to pull human-readable marker information from the js loaded into the page, not how to create an exportable list of the marker data.

From poking around in the javascript console, I can find what look like a series of related auto generated JS files in sites/default/files/js; but the JS looks like it contains the functions to create the markers and map definitions, not the geometry collection itself. Similarly, the gmap\_markers.js doesn't provide much that's easy to decipher.

So, is drupal passing variables to those js scripts to create the markers on the fly? and if so, is there a place where a human-readable collection of those markers (ID, LatLon, popup info, and any other meta data) is stored and loaded into the Gmap?

# Answer
So, I got the answer from reddit.com/r/javascript. All the map settings are stored in the drupal.settings js variable, you can access it from the console in drupal.settings.gmap.auto1map.markers
> 0 votes

---
Tags: javascript, google-maps
---


# Question
Title: Hide parent term and show only second level
I'm getting frustrated figuring this out for a couple of hours. I was not able to make work what I've wanted to achieve.

I have taxonomy which has sub-child. Here is my taxonomy structure:

* Parent 1
    + Child 1
    + Child 2
* Parent 2
    + Child 1
    + Child 2

When the parent term is visited, then it will list its sub-child. Like below:-

Parent 1 title

* Child 1
* Child 2

I've created a views taxonomy terms, I don't want to use content because the term will not show if that term is empty.

In contextual filters, the taxonomy id with depth and modifier is not available.

# Answer
Assuming that when you say "When the parent term is visited" you mean at the taxonomy term page at *taxonomy/term/\[..\]*, the view settings below will work.

```
View type : Term
Display : block
Pager : Display all items

Relationships : Taxonomy term: Parent term
> Identifier: Parent

Contextual filter : (Parent) Taxonomy term: Term ID
> Relationship : Parent
  > When the filter value is not available : Provide default value
    > Type: Taxonomy Term ID from URL
    > Load default filter from term page : checked

```

If you want the parent term to appear instead of the vocabulary name, also do:

```
  > When the filter value is available or a default is provided : Override title
    > (argument) %1

```

You can also enter a space instead of "%1" to clear it since the parent term already appears by default as page title (otherwise it will appear twice).

Finally, if you want to sort by term weight, also do:

```
Sort criteria : Taxonomy term: Weight (asc)

```

Enable the block to only display on taxonomy term pages, appearing above the main page content block.

You can also do some interesting things when you combine the Taxonomy Menu and Menu Block modules.

Hope that helps!
> 1 votes

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


title: How to move VBO button to under view

text:
# Question
Title: How to move VBO button to under view
I'm just using Views Bulk Operations for the first time.

VBO augments Views " ...by showing a checkbox in front of each displayed row, and adding a select box on top of the View containing operations that can be applied."

I have it all working as it should, however, I would like to move this select box and button to UNDER the view (under the table that I am making in my view). I've been looking at this for sometime, and haven't been able to figure out how to do this. Can anyone point me in the right direction? Thanks

# Answer
You can modify the form by implementing `hook_form_alter()` either in a custom module or in *template.php* in your theme.

Here's a code snippet that brings the table above the other form elements by lowering its weight (source):

```

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form_id,  'your_vbo_form_id') !== FALSE) {
      $form['output']['#weight'] = -99; //Decrease the weight of output to rise it above other elements.
  }
}

```
> 3 votes

---
Tags: views
---


title: How do I build a hierarchical form?

text:
# Question
Title: How do I build a hierarchical form?
In Drupal 8, I don't understand how build a "hierarchical" form.

I have this sample form

```
...
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['description'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['description']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['description']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['content'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['content']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['content']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

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

public function submitForm(array &$form, FormStateInterface $form_state) {
    dpm($form_state->getValues(),"getValues");
}
...

```

When I submit my form, my form\_state-\>getValues() return :

The form\_state-\>getValues() contains only the \['content'\]\['subfirst'\] and \['content'\]\['subsecond'\] values... That means I must use uniques labels with the form api ? I find it weird...

Then, I change my form :

$form\['content'\]\['subfirst'\] become $form\['content'\]\['totosubfirst'\]

$form\['content'\]\['subsecond'\] become $form\['content'\]\['todosubsecond'\]

The new code :

```
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['description'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['description']['subfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['description']['subsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

    $form['content'] = array(
        '#type' => 'fieldset',
        '#title' => t('Main description'),
    );
    $form['content']['totosubfirst'] = array(
        '#type' => 'textfield',
        '#title' => t('subfirst'),
    );
    $form['content']['totosubsecond'] = array(
        '#type' => 'textfield',
        '#title' => t('subsecond'),
    );

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

```

And when I submit my form, my form\_state-\>getValues() return :

I get the four values. But, they are in the same hierarchical level. How I use the form api for have a form\_state like this :

'description' =\> 'subfirst' =\> string(3) "AAA"

'description' =\> 'subsecond' =\> string(3) "BBB"

'content' =\> 'totosubfirst' =\> string(3) "CCC"

'content' =\> 'totosubsecond' =\> string(3) "DDD"

?

I want get a hierarchical form\_state because after I want create a custom function like :

```
foreach element in description
  do that
foreach element in content
  do that
...

```

# Answer
> 5 votes
Set #tree =\> TRUE on the parent elements, then the values will be nested accordingly

---
Tags: forms, 8
---


# Question
Title: How do I export data into yaml with mapping?
I am exporting module's libraries from PHP in modulename.libraries.yml. I am using the YAML parser.

```
\Drupal::service('serialization.yaml')->decode($data)

```

The issue I have encountered is that I cannot indicate JavaScript or CSS files to be minified because instead of `filename: { minified: true }` I will end up with the following.

```
filename:
  minified: true

```

Basing on a brief IRC chat, I get this is not possible. Is that correct? If it is so, is this a bug? Differently, can anybody tell me how can I achieve this?

# Answer
> 1 votes
Those two are semantically the same thing. The only difference is that the {} format is more compact. See the output in these two links.

Regardless, the second argument to the dump method lets you configure the verbosity of arrays. See Writing YAML Files.

---
Tags: theming, 8
---


# Question
Title: Is it okay to store a $node object as a $_SESSION variable
My contrib module currently stores a `$node` object temporarily in the `variable` table, and stores the `nid` for that `$node` in the `$_SESSION` variable so that the `$node` can be retrieved from the variable table at a later point.

Would it be okay to store the `$node` directly in the `$_SESSION` variable? Or would there perhaps be a performance of security impact?

If it is okay to store a $node object in the `$_SESSION` variable, do I need to serialize it first?

# Answer
> 1 votes
I think you want the ctools object cache API here, this is what views uses to store edits to a view until they are saved and is what Drupal 8 uses for node preview. In D8 it's called user temp store.

# Answer
> 0 votes
Your concerns and this answer point toward no, storing objects in session is bad practice for security and performance. If you dont want to create your own table to track these items, you can also use the `data` field in the user table/object. This data is also serialized.

However, as your question is written, "yes" you "can" store nodes in $\_SESSION... php/drupal will allow it. But as mentioned, this is bad practice.

---
Tags: 7, sessions
---


title: multiple submit button

text:
# Question
Title: multiple submit button
I have two submit buttons in two field . My problem is that if I press ENTER from the field 2 of textfield , Submit 1 gets triggered instead of trigger submit 2. but submit handler works perfectly for both submit button when it is clicked.

# Answer
This is native browser functionality, you are going to need to use JavaScript to circumvent and add your own behavior
> 0 votes

---
Tags: forms
---


# Question
Title: Possible to save form "field by field" as soon as a user changes a field instead of pushing a save button at the end of the form?
Instead of pushing a save button, I would like to save user input as sooon as a field is changed. Similar to how mobile apps works. Is this possible in Drupal?

# Answer
> 0 votes
There is the Autosave module for node edit forms for exactly this use case.

---
Tags: 7, forms
---


title: Remove duplicates from field [array]

text:
# Question
Title: Remove duplicates from field [array]
I am using php in views and trying to make a custom field to remove the duplicates in \[field\_trucks\_notification\_no\_ref\_node\_eb:field\_trucks\_agency\] field, i tried to use the row-\>field\_name from the available variables in Global:PHP (output) with no luck.

```
 stdClass Object
    (
        [entity] => 268
        [_entity_properties] => Array
            (
                [search_api_relevance] => 1
                [search_api_excerpt] =>
                [search_api_id] => 268
                [field_cons_country_border] => 35604
                [field_trucks_notification_no_ref_node_eb] => Array
                    (
                        [0] => 269
                        [1] => 272
                        [2] => 278
                    )

                [field_trucks_notification_no_ref_node_eb:field_trucks_agency] => Array
                    (
                        [0] => 35617
                        [1] => 35621
                        [2] => 35617
                    )

```

EDIT: using Global:PHP field in views, How can I retrieve the values of the last field (array) above and remove duplicates?

# Answer
> 0 votes
To remove duplicates in Views, if the views advanced settings "Distinct" don't operate, have a look at Views Distinct module: https://www.drupal.org/project/views\_distinct. Really useful project and sounds better than php in views.

---
Tags: views, search
---


title: Allow Anonymous User to Access Form

text:
# Question
Title: Allow Anonymous User to Access Form
I'd like to create a form with Drupal that all users can access, but every time I try to access the form without being logged in, I get this error:

```
Access denied

You are not authorized to access this page.

```

How can I allow all users to access the form?

# Answer
Select People -\> Permissions, scroll down and adjust the permissions of Contact.
> -1 votes

---
Tags: forms, 8
---


title: How use strongarm with domain access?

text:
# Question
Title: How use strongarm with domain access?
Lets say I have 2 domains, A (Site A) and B (Site B). I achieved this with domain access module. Then with features and strongarm I would like to export `site_name` variable from both domains. How can I do it?

# Answer
What you want is the Domain Conf module which is a sub-module of Domain Access and provides you per-domain configuration.

> The Domain Access: Site Configuration module (called Domain Conf), is an optional extension of the Domain Access module. Domain Conf provides options for configuring basic settings of your affiliate sites to be different.
> 0 votes

---
Tags: features, domain-access
---


# Question
Title: Views charts with node revision date as x-axis
I have 4 nodes with a field `status` (just an example, it could have more fields). The content type is set to create revisions on every update.

What I need is to create a chart in views like the one below, using Charts and Highcharts.

So, first time I create the 4 nodes:

* 3 have `status` = `No Run`;
* 1 have `status` = `Blocked`;

After updating the 4 nodes, a new revision is created and now each node has a different status value:

* 1 have `status` = `No Run`;
* 1 have `status` = `Blocked`;
* 1 have `status` = `Passed`;
* 1 have `status` = `Not Completed`;

On the third revision:

* 2 have `status` = `Passed`;
* 2 have `status` = `Not Completed`;

... and so on...

I tried everything in views without success. I started by trying to show the data needed in table format but I can only view the latest revision, not all.

Anyone has a clue on how to accomplish this?

I'm willing to make this with code also but I would like to try views first.

Thanks!

# Answer
> 2 votes
Ok,

After some struggle, I managed to get the results I needed so, I will share how to do it. Hope it helps anyone with the same question.

At the time of this answer, this will only work with the most recent Dev version. Also, after that, you have to apply this patch. It won't work unless you make these two steps.

On your content type, check if you have the **Create new revision** option checked.

In views, create a new view to show **Content revisions** and format as **Chart**. Change the following inside views:

***===== First Display =====***

Remove the `Content revision: Content` relationship.

Remove the `Content: Published (Yes)` filter.

If you have more than one content type, the way you filter (at least I did it this way) is to add a field to the **Filter criteria** like this: `Content (historical data): [your field] (not empty)`.

Set `Use aggregation` to `yes`.

Add a `Content revision: Nid` field to the display and set aggregation to **COUNT**.

On the Chart settings, select field `Content revision: Updated date` to provide **labels** and `COUNT(Content revision: Nid)` to provide **data**.

The result is a display that shows the total of nodes for each revision (x-axis date).

***===== Second (and similar) displays =====***

Now, you create **chart add-on** displays for each of the different states/values of your data field (in my case it was a status\_field).

The settings for these displays are the same as the first one with one difference:

Add the `[your field]` field to the filter section and filter by one of the states/values. You will have to do this for each dispay, each one represents the chart for each state.

Combine the chart add-on with `parent chart`.

Finally, to get the chart as stacked, you have to create some code. Add the following code to your module:

```
function mymoudle_chart_alter(&$chart, $chart_id) {
    if ($chart_id == '[my_chart_machine_name]__[first_display_machine_name]') {
    $chart['#stacking'] = TRUE;
}

```

Notes: remove the `[` and `]` from above example but keep both undersores (`__`).

And that's it. This is the result I got:

I have the update date of the revision to show as unix timestamp but you can have it as you like!

As suggested, here is a similar chart but using 'bar' type:

---
Tags: views, charts
---


title: Site won't display messages

text:
# Question
Title: Site won't display messages
I'm desperate. I have a site with 2 databases, staging and production, and in staging messages set with drupal\_set\_messages() appear, but in production they don't. The codebase is the same. I tried switching database settings on the same codebase and the behavior will change depending on the database. I have inherited the site so I'm not 100% familiar with its configuration.

My question is: is there anything on a database level that can block messages from showing? They appear in the admin area, but not in the rest of the website...

# Answer
> 2 votes
`Configuration > Development > Logging and errors` has some settings on whether to display drupal messages or not. You might check to make sure that it is properly configured for your use case.

Path to config page: /admin/config/development/logging

# Answer
> 0 votes
Check your module page. There are modules such as Disable messages. Is any such module enabled on production.

---
Tags: status-messages
---


# Question
Title: Use drush to put a site in maintenance mode
`drush @mysite cget system.maintenance` shows:

> message: '@mysite is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en

Drupal 8 uses state values to record transient state, so `drush @mysite sget system.maintenance_mode` gives me a `1` or a `0`.

But, try as I may, I cannot see how to set the boolean. I've tried:

```
$ drush @mysite sset system.maintenance.mode "TRUE" --format=boolean
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode "TRUE" --format=auto
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode true --format=auto
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode true --format=boolean
$ drush @mysite sget system.maintenance_mode
0

```

What's the secret?

# Answer
`system.maintenance_mode` is not a boolean, it is an integer:

```
drush ev "var_dump(\Drupal::state()->get('system.maintenance_mode'));"

```

Result:

```
int(0)

```

The answer to the question, how to use drush to put a site in maintenance mode:

```
drush sset system.maintenance_mode 1

```
> 29 votes

---
Tags: drush, 8
---


# Question
Title: Hook to replace custom tags in block showing related articles
I use a single drupal8 installation to serve content for multiple website's FAQ section. So I have put some custom tags like "##website\_name##" in the html in article content and title.

Depending on the current domain, the tags get replaced. I have successfully replaced the tags in article content and title while displaying article page.

I have also created a block view to show related articles to the current article depending on the taxonomy of the article.

Problem is the tags I had placed in article title is not getting replaced when the related article block is replaced.

```
    function my_module_preprocess_views_view_unformatted(&$variables)
    {
        $rows = $variables['rows'];
        foreach ($rows as $id => $row)
        {
            $variables['rows'][$id]['content']['#row']->_entity->get('title')->value
                = replace_tags_in_content($variables['rows'][$id]['content']['#row']->_entity->get('title')->value);
        }
    }

```

Also tried following code:

```
function my_module_preprocess_block(&$variables)
{
        if ($variables['plugin_id'] == 'views_block:related_articles-block_1')
        {
            $results = $variables['content']['#view']->result;

            foreach ($results as $key => $result)
            {
                $title = $variables['content']['#view']->result[$key]->_entity->get('title');
                $variables['content']['#view']->result[$key]->_entity->get('title')->value = replace_tags_in_content($title->value);
            }
        }
}

```

When I inspect the title value in debugger, values are getting replaced but when the output is shown on the page the custom tags are still present.

Following the the screen shot for the view setting:

# Answer
> 0 votes
This is not easy to solve in preprocess, it is better to do this earlier when the view() of the node is executed, for example:

```
function mymodule_NODE_view_alter(&$build) {
    if ( isset($build['body']['0']['#text']) ) {
      $build['body']['0']['#text'] = replace_tags_in_content($build['body']['0']['#text']);
    }
}

```

This works, no matter if the node is used as page or in views (as content).

You might run into caching issues, when you make changes, that are not coming from the database and drupal does not know, which cache tags have to be invalidated. This would be a version of this code to address this:

```
function mymodule_NODE_view_alter(&$build) {
    $nocache = false;
    if ( isset($build['body']['0']['#text']) ) {
      $build['body']['0']['#text'] = replace_tags_in_content($build['body']['0']['#text'], $nocache);
    }
    if ( $nocache ) {
      $build['#cache']['max-age'] = 0;
    }
}

```

You have to set $nocache in the function `replace_tags_in_content($string, &$nocache)` to true, if you change dynamic data from outside.

---
Tags: hooks, 8
---


title: Not showing the URL pattern option

text:
# Question
Title: Not showing the URL pattern option
Drupal 8, When we go to URL aliases section, there is no URL pattern option like Drupal 7.

Do I need to install any other modules to have this feature available?

**Edit**

Added screenshot

**Drupal 8**  **Drupal 7**

# Answer
Those options are provided by the Pathauto module.

At time of writing, the Drupal 8 version of Pathauto is unfortunately not usable; you can follow progress here
> 2 votes

---
Tags: 8, path-aliases
---


# Question
Title: How to set the url alias of a node created by Rules?
I am using the Rules module to create some default group content upon creation of an organic group. The rule is copied below and works well except that the url pattern for the default content is not being generated as I want it to be.

I would like url pattern to be \[node:og-group-ref\]/content/\[node:title\] and I have this working for regular group content which is created manually once a group exists.

The problem is that default content created by rules is missing \[node:og-group-ref\] in the url. If I edit the generated content I see that the setting to 'Generate automatic URL alias' is unchecked. If I then enable this and re-save the url ends up as I need it.

And I am guessing that pathauto is not aware of the og-group-ref value when the node is first created by rules and can not use this token.

I have tried including an action to create a url in the rule, but this seems to get overriden by pathauto.

So my question is - How to set the url alias of a node created by Rules?

```
{ "rules_og_create_group_content_timetable" : {
"LABEL" : "OG Create group content - Timetable",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "og" ],
"ON" : { "node_insert--og_group" : { "bundle" : "og_group" } },
"DO" : [
  { "entity_fetch" : {
      "USING" : { "type" : "node", "id" : [ "node:nid" ] },
      "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
    }
  },
  { "entity_create" : {
      "USING" : {
        "type" : "node",
        "param_type" : "og_page",
        "param_title" : "[entity-fetched:title] Timetable",
        "param_author" : [ "node:author" ]
      },
      "PROVIDE" : { "entity_created" : { "entity_created__page_stub" : "Created entity page stub" } }
    }
  },
  { "entity_save" : { "data" : [ "entity-created--page-stub" ], "immediate" : "1" } },
  { "og_group_content_add" : {
      "entity" : [ "entity-created--page-stub" ],
      "group" : [ "entity-fetched" ]
    }
  }
]

```

} }

# Answer
It is probably because you have not "made that field available yet to Rules".

To do so, add a "Rules condition" like "Entity has field", and use that "\[node:og-group-ref\]" in that condition to be added.

Not sure if it is the ONLY problem you have, but for sure something you should add to your rule.
> 0 votes

# Answer
I am not sure how to get PathAuto and Rules to work together, but you can set the **Title** of the node you are creating in Rules before saving it (set it to the same tokens you are using in PathAuto, but make sure they are all available in your rule, renaming as necessary). The danger of this approach is that if you change the PathAuto title string for your node then you also have to update the rule, and if you forget, then you will have content generated with two different passwords.

However, if it is highly unlikely that you will be making changes to the alias later, this is a reasonable approach.
> 0 votes

---
Tags: rules, organic-groups, path-aliases
---