# Question
Title: Why is HTML rendering as Plain Text in a simple 'title' alteration?
I have been able to change each node's Comment Link 'title' text (that on default renders 'Add new comment') with the below code, but if I add HTML, it renders as plain text. I'm trying to add a FontAwesome icon before this text `<i class="fa fa-comments" aria-hidden="true"></i>`

```
function MODULE_node_view_alter(&$build) {
  $node = $build['#node'];
  if (isset($build['links']['comment']['#links']['comment-add'])) {
    $build['links']['comment']['#links']['comment-add']['title'] = '<i class="fa fa-comments" aria-hidden="true"></i> Add Comment';
  }
}

```

All I have passed is a $build parameter, but I am unsure of whether or not this is the issue.

Any ideas?

# Answer
> 1 votes
You can render HTML in links by setting the `html` option to `TRUE`. Check theme\_links() to see all options.

For example

```
theme('links', array(
  'links' => array(
    'title' => '<span>Title</span>',
    'href' => 'node/1',
    'html' => FALSE, // default
  )
))

```

would result in the span tag being escaped, while

```
theme('links', array(
  'links' => array(
    'title' => '<span>Title</span>',
    'href' => 'node/1',
    'html' => TRUE,
  )
))

```

would render the span tag as html.

So in your case you need to add the following row.

```
$build['links']['comment']['#links']['comment-add']['html] = TRUE;

```

# Answer
> 0 votes
Titles do not support HTML markup. This is AFAIK a security countermeasure.

There was an HTML Title module but it can no longer be downloaded because of unfixed security issues.

If you want to add an icon, you can add it to the form as `#markup` and then just adjust the placement as needed.

---
Tags: views, theming
---


# Question
Title: hook_menu() and collapsable menu items with wildcard
I've defined a few routes with `hook_menu()`, and added these routes to a menu with nesting. This works fine for all static routes, but for any route with a wildcard the 'active-trail' does (understandably) not apply to the menu, and the parent menu item is collapsed. How can I enforce that the parent menu item is open and has 'active-trail' class?

This is the `hook_menu()` implementation I am using.

```
function my_module_menu() {
  $items['parent'] = array(
    'title' => t("Parent"),
    'page callback' => 'my_module_parent',
    'access callback' => 'user_is_logged_in',
  );
  $items['parent/child'] = array(
    'title' => t("Child"),
    'page callback' => 'my_module_child',
    'access callback' => 'user_is_logged_in',
  );
  $items['parent/child/%'] = array(
    'title' => t("Child Item"),
    'page callback' => 'my_module_child_item',
    'access callback' => 'user_is_logged_in',
    'page arguments' => array(2)
  );

  return $items;
}

```

My menu (a custom menu) looks like the following.

* Home
    + Item 1
    + Item 2
    + Parent
        - Child

So if I go to 'parent/child/123' I want the 'parent' and 'child' menu items to be active and not collapsed.

I've tried the Menu Trail by Path module, but it seems to have no effect.

# Answer
I solved the problem with the Link Trail By Path module. This module add active class for 'parent' and 'child' link.
> 1 votes

# Answer
Found I can achieve this with menu\_set\_active\_item('parent/child');
> 0 votes

---
Tags: 7, routes
---


# Question
Title: Why is a template being looked in a theme and not in my module?
I have created a custom module. in that module I have create a custom twig template using `hook_theme` function

```
function mymodule_theme($existing, $type, $theme, $path) {
  return array(
    'mymodule_settings' => array(
      'variables' => array(
        'role' => NULL,
      )
    )
  );
}

```

Then I created a custom block using my module here is the code of the block

```
public function build() {
    $config = \Drupal::config('mymodule.config');
    $role = $config->get('role');
    return array(
      '#theme' => 'mymodule_settings',
      '#role' => $role,
    );
  }

```

I created a templates directory in my module and inside that directory I have created `mymodule-settings.html.twig` file.

Cleared the cache but Drupal gives me the following error.

```
Twig_Error_Loader: Template "themes/subtheme/templates/mymodule-settings.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "themes/subtheme/templates/mymodule-settings.html.twig" in the Drupal theme registry.). in Twig_Loader_Chain->getCacheKey() (line 45 of themes/basetheme/templates/block.html.twig).

```

My theme is a subtheme. Why Drupal is looking for the template in the theme and not in my module?

# Answer
> -1 votes
Try like this:

```
function mymodule_theme($existing, $type, $theme, $path) {
  return array(
    'mymodule_settings' => array(
      'variables' => array(
        'role' => NULL,
      )
      'template' => 'mymodule-settings',
    )
  );
}

```

You are missing to define template.

---
Tags: theming, 8
---


# Question
Title: Drupal 8 - What is the format for viewsreference arguments?
I am using a views reference field inside a paragraph on a node. I know that I may add optional arguments but how should I format the arguments? Two things I would like to do are: \- Limit the number of results returned in the view to 3 \- Display only results with a certain taxonomy term

Here is a screenshot of the arguments field in the paragraphs UI.

# Answer
> 0 votes
I'm see code `ViewsReferenceFieldFormatter.php`.

The argument field is treated as follows:

```
if (preg_match('/\//', $argument)) {
  $arguments = explode('/', $argument);
}

```

Hence argument have next format: `tid/nid/custom_id`

---
Tags: views
---


title: Reasons for limited login duration?

text:
# Question
Title: Reasons for limited login duration?
On a site I am working on, I get logged out almost daily. I assume there is a limit on the login duration.

I already set session.gc\_maxlifetime to a very high value, using ini\_set() in settings.php. This setting is visible in `/devel/phpinfo`.

Is there anything else that limits the login duration?

EDIT: The original problem occured on a Drupal 7 site. But I imagine that the same problem and solution would apply in Drupal 8. Maybe someone wants to confirm this in the comments.

# Answer
## TLDR

Look for session.gc\_maxlifetime and session.cookie\_lifetime.

## Inspect your session cookies with browser developer tools

To debug this, one can use browser developer tools to inspect cookie expire date.

The cookie that is relevant for login has a key = "SESS...".

An "Expire" of "Session" means that the cookie expires when the browser is closed. Most of the time this is not what you want!

You can open other Drupal sites (e.g. drupal.org) and compare the cookies. It can also be interesting to compare with other Drupal sites installed on the same server (e.g. your localhost), and with different browsers. This can give you clues whether this is a problem with your global server config or with your specific site.

## Check current PHP config in Drupal

Open `admin/reports/status/php` for current phpinfo. Look for `session.cookie_lifetime` and `session.gc_maxlifetime`.

A value of session.cookie\_lifetime === 0 causes the Expire === Session for the session cookie. This means that closing the browser causes a logout. Otherwise, the number specifies seconds of login duration.

See http://php.net/manual/en/session.security.ini.php for more information.

## Inspect your code and server config

* ini\_set() statements in your Drupal's sites/\*/settings.php
* Your .htaccess file.
* Your server settings, e.g. in /etc/apache2/apache2.conf, or /etc/apache2/sites-enabled/... grep is your friend.

Also look for modules that modify login duration, such as https://www.drupal.org/project/autologout or https://www.drupal.org/project/autologout.

## Fix.

Decide on suitable values for session.gc\_maxlifetime and session.cookie\_lifetime, and use one of the places mentioned above to set these values.

For the project I am working on, I decided to set both values to 1209600 === two weeks.
(2 * 7 * 24 * 60 * 60 seconds === 1209600 seconds)

## About the values

For more information on these values, see

From the information I found, and my understanding of it:

* session.gc\_maxlifetime is a server-side limit, but session.cookie\_lifetime is a client-side limit.
* Even when session.gc\_maxlifetime has run out, there is a chance for the session to stay alive for a bit longer, because the garbage collection only happens every once in a while (depending on session.gc\_probability and session.gc\_divisor).
* A browser or other client could ignore or override the cookie lifetime, and keep the session alive longer than intended. I assume the expire date is also stored on server side, so I assume this won't help. See https://superuser.com/questions/442218/automatically-override-cookie-expiration-on-chrome where this is being discussed.
> 4 votes

---
Tags: 7, users, sessions
---


# Question
Title: Drupal 8 Custom Twig Templates not being loaded
I am working on a website which has pages with dynamic google maps, which has made it necessary for me to make use of custom page templates. I ran into a issue earlier today and been trying to find a way around it for hours now:

I have two pages that I need to create templates for(lets call them **/dash\_a** and **/dash\_b**). I created a twig template saved as **page--dash\_a.html.twig** which loads correctly when I navigate to the page on the website. Now I created the **page--dash\_b.html.twig** but it doesn't load the template on this page surprisingly. It actually uses the **page.html.twig** template. I have tried the following:

* Cleared all caches numerous times
* Deleted the page /dash\_b and recreated it
* Disable Caching on the website
* copied the content of **page--dash\_a.html.twig** into **page--dash\_b.html.twig**, cleared cache and refreshed page just to be sure there is no error in my twig file.
* Created another page **/dash\_c** and created a corresponding **page--dash\_c.html.twig** to see if it will work but that too didn't work.

None of these could resolve my issue. Please what else is there to do to resolve this issue as it has robbed me of a whole day's work already. Any help will be appreciated.

P.S.: I am very new to Drupal and this is my first website on the platform, but I have used DNN extensively in the past.

# Answer
Can we start easy? I think 9 times out of 10 when my templates dont load it's due to file naming issues. Do the file names match what's in the database as your content type machine name?

One thing that has happened to me a couple times is I hit enter too soon when creating content in drupal. That ajax just needs a little time to catch up and fill in the machine name. Too soon and your dash\_c page could actually be named dash\_

Do you have devel enabled? Can you see the \*FILE NAME SUGGESTIONS when you "view source" of your webpage?
> 1 votes

---
Tags: theming, 8, caching
---


# Question
Title: Clearing the cache breaks the installation
I just moved my Drupal 7 installation to another server. All the domain names are exactly the same. Everything seems to work fine until I click on clear caches. That results in a HTTP 500 error which I am unable to debug since the host does not display the errors.

I have sql dump for my db that is right before I hit the clear caches so whenever I fully restore the db in that state the site is back up again. That tells me that it is a database issues but I cannot figure out what it may be.

Any ideas?

# Answer
You need to check the PhP error logs on your server for the reason for the 500 error.

A quick guess would be that your backup excluded the actual cache table structure and not just it's contents. So when the code needs to access one or more of the tables, it is not there. The log should show you the specific problem.

An alternative would be to use something like MySQL Workbench and working / non-working databases and start comparing tables between the two. Missing tables should be fairly obvious.
> 1 votes

---
Tags: caching, migrations
---


title: I cannot import a large HTML body

text:
# Question
Title: I cannot import a large HTML body
Am using content import module in drupal 8 to import nodes. For test i have defined like below

It works fine when smaller body content. But when the body is too large. Then the import is undone with no fail message.

**Test Case:**

I have unchecked the below in the configuration,

I turned on the **source** mode in ck editor and pasted large body html content. And saved the changes it works.

**Content Type:** Basic Page

**Sample Body Content(Formatted):**

Total lines will be around 500.

Is it possible to import the file attachment too?

# Answer
I have overcome by using the Migrate CSV plugin, now i can able to import large body content.
> 0 votes

---
Tags: 8, nodes, importing-exporting
---


# Question
Title: Composer does not update anymore when trying to update to 8.4
when I do an update with "Composer", the following error is displayed :

> www.s1biose.com@vps000000:~/public\_html$ composer update

```
Cannot create cache directory /home/www.s1biose.com/.composer/cache/repo/https---packages.drupal.org-8/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/www.s1biose.com/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/www.s1biose.com/.composer/cache/files/, or directory is not writable. Proceeding without cache
Gathering patches for root package.
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install drupal/core 8.4.0-rc2
    - Conclusion: don't install drupal/core 8.4.0-rc1
    - Conclusion: don't install drupal/core 8.4.0-beta1
    - Conclusion: don't install drupal/core 8.4.0-alpha1|remove symfony/event-dispatcher v2.8.27|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.27|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.26|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.25|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.24|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.23|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.22|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.21|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|remove symfony/yaml v2.8.27|install symfony/serializer v3.2.10|install symfony/serializer v3.2.11|install symfony/serializer v3.2.12|install symfony/serializer v3.2.13|install symfony/serializer v3.2.9|install symfony/serializer v3.3.8|install symfony/serializer v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.20|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.19|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.18|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.17|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.16|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.15|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.14|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.13|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.12|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.11|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.10|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.0-RC1|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.9|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.0-RC2|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.0-RC1|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.8|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.0-RC1|install symfony/event-dispatcher v3.2.0-RC2|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.0-RC1|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.7|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.0-RC1|install symfony/event-dispatcher v3.2.0-RC2|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.0-BETA1|install symfony/event-dispatcher v3.3.0-RC1|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1|don't install symfony/event-dispatcher v2.8.6|install symfony/event-dispatcher v3.2.0|install symfony/event-dispatcher v3.2.0-BETA1|install symfony/event-dispatcher v3.2.0-RC1|install symfony/event-dispatcher v3.2.0-RC2|install symfony/event-dispatcher v3.2.1|install symfony/event-dispatcher v3.2.10|install symfony/event-dispatcher v3.2.11|install symfony/event-dispatcher v3.2.12|install symfony/event-dispatcher v3.2.13|install symfony/event-dispatcher v3.2.2|install symfony/event-dispatcher v3.2.3|install symfony/event-dispatcher v3.2.4|install symfony/event-dispatcher v3.2.5|install symfony/event-dispatcher v3.2.6|install symfony/event-dispatcher v3.2.7|install symfony/event-dispatcher v3.2.8|install symfony/event-dispatcher v3.2.9|install symfony/event-dispatcher v3.3.0|install symfony/event-dispatcher v3.3.0-BETA1|install symfony/event-dispatcher v3.3.0-RC1|install symfony/event-dispatcher v3.3.1|install symfony/event-dispatcher v3.3.2|install symfony/event-dispatcher v3.3.3|install symfony/event-dispatcher v3.3.4|install symfony/event-dispatcher v3.3.5|install symfony/event-dispatcher v3.3.6|install symfony/event-dispatcher v3.3.7|install symfony/event-dispatcher v3.3.8|install symfony/event-dispatcher v3.3.9
    - Conclusion: don't install drupal/core 8.4.0-alpha1
    - Conclusion: don't install drupal/core 8.5.x-dev
    - Installation request for drush/drush ^8.1 -> satisfiable by drush/drush[8.1.0, 8.1.1, 8.1.10, 8.1.11, 8.1.12, 8.1.13, 8.1.14, 8.1.2, 8.1.3, 8.1.4, 8.1.5, 8.1.6, 8.1.7, 8.1.8, 8.1.9, 8.8.x-dev, 8.x-dev].
    - drupal/commerce 2.x-dev requires drupal/core ~8.4 -> satisfiable by drupal/core[8.4.0-alpha1, 8.4.0-beta1, 8.4.0-rc1, 8.4.0-rc2, 8.4.x-dev, 8.5.x-dev].
    - drupal/commerce 2.x-dev requires drupal/core ~8.4 -> satisfiable by drupal/core[8.4.0-alpha1, 8.4.0-beta1, 8.4.0-rc1, 8.4.0-rc2, 8.4.x-dev, 8.5.x-dev].
    - Conclusion: don't install drupal/core 8.4.x-dev
    - Installation request for drupal/commerce 2.x-dev -> satisfiable by drupal/commerce[2.x-dev].

```

What is going on ?

It worked before

# Answer
> 6 votes
I think the relevant error is `Your requirements could not be resolved to an installable set of packages.`

I had this too when I tried to update to 8.4.

If you're trying to run Drupal 8.4 you will need to use Drush 9, not Drush 8.

Change the drush line to:

`"drush/drush": "~9",`

And try again.

P.S. It's better to run `composer update drupal/core` and `composer update drupal/mymodule` one-by-one than to run `composer update` by itself. `composer update` alone will update symfony dependencies before they have been tested for compatibility with core, which can break things.

# Answer
> 0 votes
I updated to Drupal 8.4 this way and that resolved composer requirement conflicts vis a vis Drupal and Drush, but Drush 9 was unable to recognize the running Drupal site as a running Drupal site:

```
 [error]  The command could not be executed successfully (returned:

  [Exception]
  Bootstrap failed.

```

Now that https://github.com/drush-ops/drush/pull/2800 is in, dropping back to `"drush/drush": "^8.0"` worked for composer dependencies and for Drush to actually find the site.

# Answer
> 0 votes
**Requirement :** PHP 7.1
**Explanation :**
1. Doctrire, a dependancy of Drupal core, requires PHP 7.1. Doctrine uses the latest PHP 7.1 syntax to declare the methods' return type eg. `function my_function() : void {...}`
2. webflo breaks the chain of dependencies
3. Drupal 8.4 requires Drush 9.0

If you have PHP 7.1 on your server you can do the following:

1. edit the `composer.json` file: `"drupal/core": "~8.4"` and `"drush/drush": "~9.0"`
2. delete `composer.lock`
3. delete `vendor`
4. update webflo: `composer require "webflo/drupal-finder ~1.0.0"`
5. update the database: `../vendor/bin/drush updb -y`
6. update the entities schemas: `../vendor/bin/drush entup -y`

---
Tags: 8, composer
---


# Question
Title: Conflict between package requirements when updating to Drupal 8.4
When running composer update, I get the following error:

Your requirements could not be resolved to an installable set of packages.

```
  Problem 1
    - Can only install one of: symfony/yaml[3.2.x-dev, 2.8.x-dev].
    - Can only install one of: symfony/yaml[v2.8.0, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.0-BETA1, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.1, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.10, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.11, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.12, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.13, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.14, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.15, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.16, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.17, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.18, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.19, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.2, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.20, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.21, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.22, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.23, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.24, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.25, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.26, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.27, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.28, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.3, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.4, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.5, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.6, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.7, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.8, 3.2.x-dev].
    - Can only install one of: symfony/yaml[v2.8.9, 3.2.x-dev].
    - Can only install one of: symfony/yaml[3.2.x-dev, v2.8.28].
    - drupal/core 8.4.0 requires symfony/yaml ~3.2.8 -> satisfiable by symfony/yaml[3.2.x-dev].
    - Installation request for drupal/core 8.4.0 -> satisfiable by drupal/core[8.4.0].
    - Installation request for symfony/yaml ~2.8 -> satisfiable by symfony/yaml[2.8.x-dev, v2.8.0, v2.8.0-BETA1, v2.8.1, v2.8.10, v2.8.11, v2.8.12, v2.8.13, v2.8.14, v2.8.15, v2.8.16, v2.8.17, v2.8.18, v2.8.19, v2.8.2, v2.8.20, v2.8.21, v2.8.22, v2.8.23, v2.8.24, v2.8.25, v2.8.26, v2.8.27, v2.8.28, v2.8.3, v2.8.4, v2.8.5, v2.8.6, v2.8.7, v2.8.8, v2.8.9].

```

I've seen a few explanations for similar errors, but I can't figure out how to fix it. I assume it has something to do with incompatibilities between yaml versions. How do I go about solving this?

# Answer
> 4 votes
So, I've found a solution. I had to go into my **composer.json** file and specific these versions under require:

```
"drupal/core": "~8.4",
"drush/drush": "~9.0",

```

Once I updated those lines, I deleted the **composer.lock** file as well as the **vendor** directory. After that, I was able to install **Drupal 8.4** using `composer update --with-dependencies`.

# Answer
> 0 votes
This is what worked for me

**Requirement :** PHP 7.1
**Explanation :**
1. Doctrire, a dependancy of Drupal core, requires PHP 7.1. Doctrine uses the latest PHP 7.1 syntax to declare the methods' return type eg. `function my_function() : void {...}`. There is a core bug concerning this issue with status "Needs work". Even if this bug is patched, 8.4 requires PHP 7.
2. webflo breaks the chain of dependencies
3. Drupal 8.4 requires Drush 9.0

If you have PHP 7.1 on your server you can do the following:

1. edit the `composer.json` file: `"drupal/core": "~8.4"` and `"drush/drush": "~9.0"`
2. delete `composer.lock`
3. delete `vendor`
4. update webflo: `composer require "webflo/drupal-finder ~1.0.0"`
5. update the database: `../vendor/bin/drush updb -y`
6. update the entities schemas: `../vendor/bin/drush entup -y`

Applied on three different production servers (Linux + Apache) and on local environments (macOS + Apach, Ubuntu + Apache). Not tested with Vagrant.

The two entity updates are concerning "*paragraph entity type*" : (1) The Published field needs to be updated. (2) The Behavior settings field needs to be updated.

---
Tags: 8, updating, composer
---


# Question
Title: 8 - How do I check if a comment is from original poster?
I have a page where written articles are displayed. The following is a article written by `Canada_Girl1993`.

>

As you can see, the author of the article is displayed at the top.

Now, other users are able to comment on this article, as well as the author of the article. But how can I check if a comment is from the author of the article, so that I can add some styling or html to it?

>

# Answer
> 1 votes
Actually, before you write any code... D8 automatically adds a 'by-\[entity-type\]-author'(e.g. by-node-author) class to the `<article>` tag of each comment, if commenter and author are the same.
This is defined at line 73, in comment.html.twig file(at least this is the case in Bartik theme file), so please take advantage of it :)

---
Tags: 8, nodes, users, comments
---


title: Programmatically create a discount code

text:
# Question
Title: Programmatically create a discount code
Does anyone know how to programmatically create a discount code in Drupal Commerce?

# Answer
> 0 votes
The best solution is to always review the tests. The tests create promotions and coupons programmatically.

Here's how to create a promotion.

```
$promotion = Promotion::create([
  'name' => 'Promotion test',
  'order_types' => ['default'],
  'stores' => [$this->store->id()],
  'offer' => [
    'target_plugin_id' => 'order_percentage_off',
    'target_plugin_configuration' => [
      'amount' => '0.10',
    ],
  ],
  'start_date' => '2017-01-01',
  'status' => TRUE,
]);
$promotion->save();

```

And then coupons.

```
$coupon = Coupon::create([
  'promotion_id' => $promotion->id(),
  'code' => 'coupon_code',
  'usage_limit' => 1,
  'status' => TRUE,
]);
$coupon->save();

```

---
Tags: 8, commerce
---


title: Different front page per language

text:
# Question
Title: Different front page per language
Is there any way to provide a different node ID per language for the front page setting in Drupal 8?

We need a different front page for a specific language. In Drupal 7, this was easy.

# Answer
Technically, the config override API that config translation uses allows any kind of override of configuration.

The core config translation however only does translation, meaning it only allows to change things that are classified as user-facing texts and not technical strings.

What you want is usually referred to as localization, changing things based the language that isn't actually a "translation". There is a core issue to better support this, https://www.drupal.org/node/2275865, but it hasn't been updated in quite some time.

There are a few possible workarounds, though:

* Since you mention nodes, in Drupal 8, translations of nodes have the same ID/URL. That means you could have your different front pages as translations of the same node. That would be problematic if you use Paragraphs for example, as that doesn't currently support translatable fields, so you'd be forced into the same structure.
* You could use Page Manager to have different front pages (there is a per-language constraint necessary, which has a patch but has not yet been committed) or even just a view that selects a node based on a certain condition (like filtered by language of a certain type).
* A custom callback that displays a certain node based on a bit of code.

Update:

4 years later, I had this use case too and still no activity on the core issue. As a workaround, I altered the config schema and made the front\_page a label type to be able to translate it. Not fully tested yet, so beware of dragons:

```
function custom_config_schema_info_alter(&$definitions) {
  // Change the front page type to label so that it can be translated.
  $definitions['system.site']['mapping']['page']['mapping']['front']['type'] = 'label';
}

```
> 6 votes

# Answer
Another way to have a homepage per language, or just about any config override per language is to use config override system. I created a ticket in config\_override module to add language overrides support and there is a patch attached: https://www.drupal.org/node/2914987

In short, you would be able to create a folder in your codebase with language overrides, where each language will have it's own subfolder and config override will merge config keys from language overrides with the active configuration.

Example of usage: Include language\_override config key in settings.php

```
$config_directories['language_override'] = '../config_override/language';

```

Place an override file in 'language\_override' folder following core's config\_translation structure: \[language\_override\]/en/system.site.yml

```
page:
  front: /node/123

```

The patch is in review, but you could install the module and apply the patch easily to get this feature.
> 2 votes

# Answer
Make a view that provides a block for each language. Master has no output, Content: ID (\< 1).

For Language set Rendering Language: Content language of view row (default).

If you want to display a full node on some language's front page, use Format -\> Show: Content | Full content, and for Filter criteria use Content: ID (= 123).

Create a node with no content. Make this node your front page in Basic Site Settings -\> Default front page. Translate this node for all languages.

Place the blocks at Content region, no title, configure them with language restriction and with Pages restriction, show only on the node you set as your front page.

If you are displaying a full node on one some blocks, include the title in block configuration. The title being shown then is not the node title, but the block title. This will be h2, that needs to be styled like h1.

This is trickier than I remembered, but possible.
> 1 votes

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


# Question
Title: How to hide the link for creating certain content type?
I am trying to make a reservation system for equipment in a laboratory. People reserve equipment by creating "reservation" nodes. Some fields in the reservation node already have values, determined by the way the (registered) users reached the "form", and the values can´t be changed by them. I don´t want the registered users to have access to create the reservation node through the "Add content -\> Create Reservation node" way. How to "hide" that option in the add content menu? (as they do have permission to create the reservation node)

# Answer
> 0 votes
If you want to simply get rid of link, you can go to http://example.com/admin/structure/menu/manage/navigation (substitute example with your domain) and remove the entry. This will not block direct access to http://example.com/node/add/reservation \- if you are using custom module for that, consider blocking node creation in http://example.com/admin/people/permissions \- your module can create nodes for them even when you remove "create node ... " permission there.

# Answer
> 3 votes
In drupal 8, you can remove certain links from the /node/add page hook\_preprocess\_node\_add\_list():

```
function mymodule_preprocess_node_add_list(&$vars) {

  // Remove a few content types from /node/add page.
  $types_to_remove = [
    'dog',
    'cat',
    'fox',
    'rabbit',
  ];
  foreach ($types_to_remove as $type) {
    unset($vars['content'][$type]);
    unset($vars['types'][$type]);
  }
}

```

If you are using the admin\_toolbar for drop-downs, you can remove links using hook\_menu\_links\_discovered\_alter().

```
function mymodule_menu_links_discovered_alter(&$links) {

  // Remove a few "node add" pages from admin menu.
  $types_to_remove = [
    'dog',
    'cat',
    'fox',
    'rabbit',
  ];
  foreach ($types_to_remove as $type) {
    unset($links['node.add.' . $type]);
  }
}

```

---
Tags: nodes, users
---


# Question
Title: Site gives 500 error or malformed page in place of WSOD and useful error reporting
I don't think I have encountered this before. Generally if there's a php error on page, I'm met with a WSOD. With error reporting on, the error, file, line number, etc are displayed on the page.

With this site, the site either returns a 500 error (if the error is in hook\_form\_alter, for example), or the page will load partially up to the point of the error and display sans stylesheet/other resources (if the error is in a template file).

Any ideas why this might be and how to change it over to expected behavior?

# Answer
> 0 votes
Turns out that somebody had previously hardcoded turning off error reporting somewhere in the middle of settings.php. Removed those lines and now all errors are showing up as expected.

# Answer
> 2 votes
Fixing such errors is a panic, as in comments you have tried php debugging.

Below tries may help:

1- Try to install new drupal site locally to ensure that your machine and required programs for drupal "If you don't have any working drupal site" works fine, If you faced problems in the installation fix them till you have successful installation.

2- Try to flush cache and running cron from the admin interface if it works or using drush by drush you can see latest log messages using commands "wd-list, ws".

3- Implement hook\_init in any custom module and print any message after that call drupal exit to see tha messages in the browser.

4-disable "without uninstall in order not to loose configurations" last enabled custom or contributed modules, If you have drush installed try

> drush dis Module\_name -y

Or from phpmyadmin

> Delete from system where name='Module\_name';

I used these steps before to solve similar situation and I remember it was from one the contrib modules.

If you still have the problem these guides may help.

Fixing white screens step by step

Blank pages or "white screen of death" (WSOD)

---
Tags: 7
---


title: how to retrieve a node's file name

text:
# Question
Title: how to retrieve a node's file name
I can't find the info through any search string I can think of. I need to retrieve the complete path including the filename for a file stored by a node.

public://module\_name/filename.ext I can get the public://module\_name part but not the file name. I think I am having a basic misunderstanding on how Drupal stores files. I have written a custom module and it puts the file where I specify: public://my\_module. If the file is an Image (jpg) there is no problem. I can display the file name with the generic file format. so I know that the information is available, I just cant figure out how to access it.

can any one point me at an example, API description or tutorial that covers how to access a file in the current node?

# Answer
This is not the 100% correct way of doing it because I'm accessing the property manually and I'm also generating the image html which can be automatically generated but maybe it can help as a simple example. In your theme's node.tpl.php write:

```
<?php
if (isset($node->your_field[LANGUAGE_NONE][0])) {
    $o_img = $node->your_field[LANGUAGE_NONE][0];
    $s_uri = $o_img['uri'];
    $s_url = file_create_url($s_uri);
    $s_html = "URI: {$s_uri} | URL: {$s_url}";
    print $s_html;
}
?>

```

Regards

**EDIT:** How to better read a field (I haven't tried with image fields). Notice you don't have to specify the language because everything is automatically handled by Drupal based on your language preference and fallback configuration.

```
$aa_fields = field_get_items('node', $node, 'my_field');
foreach ($$aa_fields as $a_field) {
    $a_rendered_field = field_view_value('node', $node, 'my_field', $a_field);
    $s_html = $a_rendered_field['#markup'];
}

```

In order to avoid creating clutter in your node template file, it's better to move this code to your theme's template.php or, if you plan to use your code with other themes, to your own custom module.
> 0 votes

# Answer
I looked at the functional code today and I find that the problen lies in the definition of $vaariables. In the functional code I can retrieve the path to the jpeg image as $variable\['filepath'\] in the non functional code the path does not include the file name. So $varable is not being befined propperly in my new module. I will have to study up on it. I do have some references to the subject. Thanks for the help and advise.
> 0 votes

---
Tags: entities
---


# Question
Title: How to create a lightweight domain access alternative in Drupal 7
I have a password protected site mainly used for internal management of projects, but have regularly the need to publish some of its content for clients.

For simplicity sake, I would prefer to keep all content in the same database and site. However, the published content should be viewable from another domain name.

The contrib module 'Domain access' is too heavy for my needs. I'm looking for an alternative that 'simply' allows content to be published to a second domain using something like a setting or toggle per entity.

Experiences in this area are very welcome.

# Answer
> 0 votes
Out of the box drupal 7 installs are domain agnostic (don't save absolute urls in content or as paths). Assuming you haven't got any custom server directives or alternate domain with a need for a different relative url, you could try either:

A) Create a separate content type, if content managers know up front what content will need to be visible.

B) But if they don't know up front (and since you can't easily convert a node from one type to another), you could try using a taxonomy field to tag content for visibility. Then use taxonomy access lite module (https://www.drupal.org/project/tac\_lite) to grant access to nodes tagged with a specific term to anonymous users.

---
Tags: 7, users, domain-access
---


# Question
Title: How to change the SID of webforms to increment from a new starting number
We launched a new website that uses webforms but need to make sure our webforms are using an SID for results larger than the last number used on the old site.

Please note that I am not referring to the serial for the webform submission but Drupal's SID.

For example, on the new site, the first submission ID was 1. I need it to be 10000.

# Answer
> 0 votes
If it's a Drupal 7 site:

1. Edit the webform.
2. Go to the "Form settings" subtab of the Webform tab.
3. Scroll down and expand the Advanced Settings section. There's an exposed field for the Next submission number.

---

If it's a Drupal 8 site:

1. Edit the webform.
2. Go to the "settings" subtab of the Webform
3. Scroll down and expand the Submission Settings section. There's an exposed field for the Next submission number.

---
Tags: 7, webforms
---


# Question
Title: Access denied to my route, created in module.routing.yml
I'm having a hard time trying to figure out why my custom route is returning a 403 status.

My `routing.yml` file:

```
lightbox.content:
  path: '/lightbox/content'
  defaults:
    _controller: '\Drupal\lightbox\Controller\LightboxController::content'
    _title: 'Hello World'
    requirements:
      _permission: 'access content'
      _access: true

```

My `permissions.yml` file

```
access content:
  title: 'Access Content'
  description: 'Read all content'

```

Permission page:

# Answer
> 2 votes
The issue, as mentioned in the comment was my indentation. I will leave this for anyone that may run into this issue.

---
Tags: 8, routes, users
---


# Question
Title: How to exclude a hook function from the hook list?
For example, there is some module (some\_module). The module contains some hook (some\_module\_some\_hook). I need to this hook function didn't execute. For example, I'm not satisfied its code and I want to refactor it, but don't want to use patches.

Is there an opportunity to switch off this hook function (some\_module\_some\_hook) ? For example, I want to switch it off and define in my module a new function implements this hook but having my code. How to do it in Drupal 7 ?

# Answer
You can implement `hook_module_implements_alter()`. For example to remove the cron hook from the system module:

```
function MYMODULE_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'cron') {
    unset($implementations['system']);
  }
}

```
> 3 votes

---
Tags: 7, hooks
---


# Question
Title: Responsive Image Module not reducing the file size when resizing the browser (Drupal 8)
I have an issue using `Responsive Image Module` for drupal 8 that I can't seem to solved or figure out. As shown in this screenshot the file size of the original image is `685kb`. But once I started to resize to the first breakpoint which is around `1366px` the file size jumps to `1023kb` or `1mb`. My expectations was the file size should be reduced to even smaller size. I tried the option `Resize` and setting different dimensions proportionally or even `Scale`. But I still get the same results

# Answer
> 0 votes
I guess the 685kB is your original, uploaded file and the 1MB file is generated on the webserver by GD or ImageMagick.

When your original file is heavily compressed and at the same time your JPG quality setting is very high, the generated (pixel-smaller) files can be (byte-wise) larger than your original. There is not much you can do against this except reducing JPG quality settings in **`Configuration > Media > Image Toolkit`**

Another option would be using a modified JPG library like MozJpeg, but this is beyond the scope of Drupal.

---
Tags: theming
---


title: image optimize Issue

text:
# Question
Title: image optimize Issue
I have installed S3 File System module, and all image files are served from AWS S3 bucket. The images served from S3 are not compressed. How to compress those images?

Following is the message I get when checking with page speed:

> Compressing https://example.s3-us-west-2.amazonaws.com/s3fs-public/test.jpg could save 22.4KiB (26% reduction).

# Answer
When uploading images into Drupal, those are uploaded as it is and not compressed. To compress them you can check Image Optimize (or ImageAPI Optimize) Module.

Another solution is to add custom code in your custom module, which will compress image before a record is inserted into `file_managed` table, check code below:

```
/**
 * Implements hook_file_presave().
 */
function [MODULE_NAME]_file_presave($file) {
  if (!empty($file->filemime) && (strpos('image', $file->filemime) >= 0)) {
    $compressed = _[MODULE_NAME]_compress_image($file->uri, $file->uri, 75);
  }
}

/**
 * Helper function to compress images while uploading.
 *
 * @param string $source_url
 *   Source image URL.
 *
 * @param string $destination_url
 *   Destination image URL.
 *
 * @param string $quality
 *   Percentage of Image quality to compress.
 */
function _[MODULE_NAME]_compress_image($source_url, $destination_url, $quality) {
  $source_url = drupal_realpath($source_url);
  $destination_url = drupal_realpath($destination_url);

  $info = getimagesize($source_url);

  if ($info['mime'] == 'image/jpeg') {
    $image = imagecreatefromjpeg($source_url);
  }
  elseif ($info['mime'] == 'image/gif') {
    $image = imagecreatefromgif($source_url);
  }
  elseif ($info['mime'] == 'image/png') {
    $image = imagecreatefrompng($source_url);
  }
  else {
    return FALSE;
  }

  //save file
  imagejpeg($image, $destination_url, $quality);

  //return destination file
  return $destination_url;
}

```

**NOTE:** Change **\[MODULE\_NAME\]** with your module name.
> 0 votes

# Answer
Give reSmush.it image style optimizer a try. It allows you to set which image styles should be optimized. It uses the excellent and free https://www.resmush.it/ API.

reSmush.it module works perfectly with s3fs (we are using it on all projects as well).
> 0 votes

---
Tags: media, files
---


title: Drupal 8 missing filter view schema

text:
# Question
Title: Drupal 8 missing filter view schema
After run unit tests i am getting fail

```
Schema errors for views.view.example_form_element with the following errors: views.view.example_form_element:display.default.display_options.filters.my_module.expose.example_element missing schema

```

I understand the error but i can't solve it. I tried a lot of combinations of schema.yml file name and content but without success result.

I will point out, that module name is

> my\_modules

but

> example\_element

is under

> my\_module

current file looks like

# file config/schema/my\_modules.views.schema.yml

```
views.filter.views_example_element:
  type: views_filter
  label: 'xxx'
  mapping:
    expose:
      type: mapping
      label: 'Exposed'
      mapping:
        example_element:
          type: integer
          label: 'xxx'

```

# file Plugin/views/filter/ViewsExampleElement

```
@ViewsFilter("views_example_element")

```

What is wrong with it?

# Answer
Try change in `my_modules.views.schema.yml` `type` on `views.filter.many_to_one`
> 1 votes

---
Tags: views
---


# Question
Title: Any easy way of implementing a mega menu?
Im wondering if there is a easy way to implement the following dropdown menu(ive added a before hovering on a list item, and after):

If i had to do it right now, i would use a bootstrap dropdown, and basically have to create an entire module around making the paths to point in the right directions.

Do you guys know of any existing menus or any easier way of doing this?

thanks

# Answer
> 3 votes
(not a complete answer, but too much for a comment)

The main characteristic of a "mega menu" is that the contents of the menu are not limited to a simple list or tree of menu links. In your own example you have links with descriptions / subtitles, you have a picture, you have multiple columns that probably have nothing to do with a menu tree structure.

This is why you should use tools other than menu links system, for the contents of each megamenu box.

The first step is to forget you are creating a menu, and instead imagine you would be creating custom pages or blocks. How you create these, is a question for itself.

I have heard of someone who used nodes (possibly with pragraphs module), where every megamenu page is a node.

Another option would be to do something with panels.

The next question is how to anchor the megamenu contents to the actual menu items.

The person who used nodes for the megamenu pages (if I remember correctly) used a field where people specify the menu link path. Then when displaying the menu, the contents from the matching node are inserted as submenu.

You could also completely give up on the links being menu links, and instead just display node titles as toplevel items (sorted by whichever criterion), and then the rendered node as "submenus". This could be done with views, if you use a ul/li list as the style plugin (with custom classes) and a special view mode + layout for each item with its megamenu page. The special html you need would be in the custom layout.

Special attention should be given to multiple language versions, and possibly access checks for links. Maybe you use different paths in different languages?

This still requires some creativity in putting everything together.

But the main idea should be to look for solutions outside the menu links system.

EDIT: I should add: You may want to think about doing something with ajax, to let the contents of the pages load after the main page contents. If I remember correctly, the person I talked to did this somehow, I just don't remember how exactly.

Credits to https://twitter.com/rachel\_norfolk

# Answer
> 2 votes
I basically used the Responsive and off-canvas menu module in D8 and created a view of content, with a JSON output, to give men the mega-menu content that I could "collect" via a bit of jQuery and attach to the menu items lazily if (and only if) the main desktop menu `<ul>` was visible.

I speculatively submitted it to Frontend United. Not sure they want to admit people still need mega-menus, though ;-)

# Answer
> 2 votes
Just use https://www.drupal.org/project/menu\_item\_extras, it adds fields to the core Menus, no extra entities or configurations.

# Answer
> 0 votes
superfish has a D8 version yet. TB megamenu is in development, but I couldn't find it's source ...

But right now you probably have to do it on your own. You could make a view that you show as menu-item.

# Answer
> 0 votes
If you're already familiar with Drupal 7 site building with Panels module, there is a specific module that helps integrate Drupal 7 core Menu system with Mini-panels for mega menus:

Menu MiniPanels

I have built many Drupal 7 sites using this, but the 1.x version of the module depends on the QTip Jquery Library, which is very hard to wrap your brain around and theme.

Because QTip is a total PITA, I help update the 2.x module to better support integration with the Superfish module and Nice Menus module. Unfortunately I haven't had time to give the 2.x the attention it needs, and there is currently no plan to migrate this to Drupal 8 (yet) due to lack of time.

# Answer
> 0 votes
For anybody who may come across this, I tried https://www.drupal.org/project/we\_megamenu which is released recently. It works!

# Answer
> -2 votes
You can check this https://megadrupal.com/project/md-megamenu Very easy to use (I watch the video), the problem: it's not free

---
Tags: 8, javascript, theming, navigation
---


# Question
Title: Setting a field readonly rather than invisible from hook_field_access()?
I have a field that should not be visible when editing, in certain cases (depending on node state and user). It works fine using `hook_field_access()`:

```
function mymodule_field_access($op, $field, $entity_type, $entity, $account) {
  if ( ...conditions on $entity_type, $entity->type, $field['field_name'], $op...) {
    // → $op=='edit' && isset($entity->nid) so only when modifying existing content
    return FALSE;
  }
  return TRUE;
}

```

As said it works fine, and the field is not displayed at all when access is not granted.

But in some particular conditions I would like to let the field visible but readonly (grey-ed, or anything preventing to modify it) rather than hiding it.

I tried to return TRUE and before to set according attributes to the field, but until now I failed to make it works as expected. What I tested:

```
$tmp = mode_load($entity->nid);
$tmp->my_field['#attributes'] = array('readonly' => 'readonly'); // also tried to use 'disabled')
node_save($tmp);

```

I also tried:

```
$tmp->my_field['#disabled'] = true;

```

Thanks for any help.

Regards.

# Answer
> 1 votes
Try something like that :

Replace `FORM_ID` with the real form ID.

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

  if(!user_access(ADMIN_USER)){
      $form['your_field_name']['#disabled'] = TRUE;
    }

    $form['your_field_name']['#access'] = TRUE;
}

```

---
Tags: entities, hooks
---


# Question
Title: How to store values to field collection or paragraphs programmatically?
How do I store values to either a field collection or a paragraphs field programmatically?

Could somebody please provide a working code example of how you do this?

I would have a field holder containing the following three fields where I want to store down my data:

* `field_title` \- (1 value text field)
* `field_text` \- (1 value text field - long)
* `field_sources` \- (unlimited no of values text field)

Thanks for helping me out.

# Answer
> 12 votes
Paragraphs and field collections are both their own entity and the fields pointing to them are just entity referenced.

So if you want to create a node with a referenced paragraph, you first create the paragraph with all the values you want, save it, then create the node and point it to the paragraph you created.

The Paragraph demo module has example code that does exactly that in paragraphs\_demo\_install():

```
  use Drupal\node\Entity\Node;
  use Drupal\paragraphs\Entity\Paragraph;

  $paragraph3 = Paragraph::create([
    'type' => 'text',
    'field_text_demo' => 'Apart from the included Paragraph types, you can create your own simply by going to Structure -> Paragraphs types.',
  ]);
  $paragraph3->save();

  // Add demo content with two paragraphs.
  $node = Node::create(array(
    'type' => 'paragraphed_content_demo',
    'title' => 'Welcome to the Paragraphs Demo module!',
    'field_paragraphs_demo' => array(
      array(
        'target_id' => $paragraph3->id(),
        'target_revision_id' => $paragraph3->getRevisionId(),
      ),
    ),
  ));
  $node->save();

```

# Answer
> 1 votes
I'm on Drupal 8.3.4 with paragraphs 8.x-1.1. When I use the code in the other answer, the node gets created without any reported problem.

But when I go to view the node, I get this error: `Error: Call to a member function displaySubmitted() on null in template_preprocess_node() (line 621 of core\modules\node\node.module).`. When I try to edit it, I get this error: `Error: Call to a member function getPreviewMode() on null in Drupal\node\NodeForm->actions() (line 182 of core\modules\node\src\NodeForm.php).`

The code in this comment worked for me.

```
use Drupal\paragraphs\Entity\Paragraph;  // Don't forget to use a little Class...

/**
 * Create a New Paragraph and attach it to it's node
 * @param int $nid
 *  The node id this paragraph should be attached to
 * @param longtext $content
 *  The body text of the paragraph
 * @param int fid
 *  The file id if any, or FALSE
 *
 */
function CUSTOM_MODULE_create_paragraph($nid, $content, $fid = FALSE) {
  $node = entity_load('node', $nid);
  $paragraph = Paragraph::create(['type' => 'PARAGRAPH_TYPE',]);
  $paragraph->set('TEXT_FIELD_NAME', $content);
  if ($fid) {
    $file = file_load($fid);
    $paragraph->set('IMAGE_FIELD_NAME', $file);
  }
  $paragraph->isNew();
  $paragraph->save();

  // Grab any existing paragraphs from the node, and add this one
  $current = $node->get('NODE_FIELD_NAME')->getValue();
  $current[] = array(
      'target_id' => $paragraph->id(),
      'target_revision_id' => $paragraph->getRevisionId(),
    );
  $node->set('NODE_FIELD_NAME', $current);
  $node->save();
}

```

---
Tags: 8, entities
---


# Question
Title: User cannot edit one custom profile field other users can
Drupal 7.

The profile field is a very simple long text, text area, filtered html. When I try to edit it in my own regular user (no admin roles) page, with the standard permissions everyone has, I can do it no problem. A specific user has reported that he cannot do it at all. A message is displayed that his permissions are insufficient instead of the editable text area. A third user was kind enough to click his own edit button and has no problem just like me.

I double checked permissions (field permissions module is in use) and they seem absolutely ok. I tried to peek inside the database but don't see anything suspicious (I may not be looking in the right tables).

# Answer
> 0 votes
Check the text format in use for the field that the user cannot edit. Even if the user has permission to edit the field, the user will NOT be able to edit the field if the data is saved in a text format that the user does not have access to.

Make sure the user's field format is also filtered HTML.

If that doesn't work, use `drush uli` to log in as the user directly without changing his/her password and look at the problem with your own eyes-- sometimes users say something can't be done when they simply don't know how to do it.

---
Tags: entities, users
---


# Question
Title: Update core keeping other composer packages
After upgrading Drupal to the last version with Drush (8.1.15) the other **`composer.json`** dependencies (e.g. drupalconsole) are removed.

Are there any way to update Drupal with Drush keeping other composer dependencies?

```
diff --git a/docroot/composer.json b/docroot/composer.json
index 6089861..b9536cf 100644
--- a/docroot/composer.json
+++ b/docroot/composer.json
@@ -4,28 +4,11 @@
     "type": "project",
     "license": "GPL-2.0+",
     "require": {
-        "ckeditor/fakeobjects": "4.6.2",
-        "ckeditor/image": "4.6.2",
-        "ckeditor/link": "4.6.2",
-        "codemirror/codemirror": "5.27.4",
         "composer/installers": "^1.0.24",
-        "drupal/console": "~1.0",
-        "jquery/geocomplete": "1.7.0",
-        "jquery/icheck": "1.0.2 ",
-        "jquery/image-picker": "0.3.0",
-        "jquery/inputmask": "3.3.7",
-        "jquery/intl-tel-input": "12.0.0",
-        "jquery/rateit": "1.1.1",
-        "jquery/select2": "4.0.3",
-        "jquery/timepicker": "1.11.11 ",
-        "jquery/toggles": "4.0.0",
-        "jquery/word-and-character-counter": "2.5.1",
-        "progress-tracker/progress-tracker": "1.4.0",
-        "signature_pad/signature_pad": "2.3.0",
-        "wikimedia/composer-merge-plugin": "~1.4"
+        "wikimedia/composer-merge-plugin": "^1.4"
     },
     "replace": {
-        "drupal/core": "~8.3"
+        "drupal/core": "^8.4"
     },
     "minimum-stability": "dev",
     "prefer-stable": true,

```

I've seen that there is a composer project for Drupal but I'm not using it in this project.

# Answer
If you have a composer based project, you probably should use composer to update it. E.g.:

composer update drupal/core --with-dependencies

Make sure to keep the composer.json, composer.lock, and docroot/vendor/composer/installed.json files in your repository.

Note: It's best to go 'all-in' with composer and use it to add and maintain modules as well as core. E.g.:

Add new module: composer require drupal/module

Update module: composer update drupal/module --with-dependencies

To manage patches, see the cweagans/composer-patches project.

You can also include various 3rd party libraries (e.g. chosen, colorbox, and the like) using your composer.json file.
> -1 votes

---
Tags: 8, drush
---


# Question
Title: How to set default reply-to address in webform?
I am using Webform Reply to module to set `Reply to address` for mails sent from webforms. This feature works fine but for each webform creation I have to set `Reply to address` because by default it will select `Default: No Reply-To address` option. But I want to select a default address as `xyz@mail.com` . So how can i achieve that?? For reference see image below:

# Answer
> 0 votes
in your form, create an email field that contains the email you want to have for your reply-to. now hide it(don't display..making it private might suit, or use css). This hidden email field value will be accessible in the component pulldown

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


# Question
Title: Page manager, Panels and theme suggestions
Page manager and theme suggestions

I have two types of layout

```
custom_2col_brick
custom_1col_landing

```

and I need to render the page according to the selected layout. basically, I needed two page template for each layout. something like the following:

```
page__custom_2col_brick.html.twig
page__custom_1col_landing.html.twig

```

Is there a way to do this?

In **Drupal 7** I could do it as follows, but panels\_get\_current\_page\_display is not working in **Drupal 8**

```
/**
 * Implements hook_preprocess_page().
 *
 * @see page.tpl.php
 */

function THEME_preprocess_page(&$variables) {

    if (module_exists('ctools') && module_exists('page_manager')) {
        $display = panels_get_current_page_display();
        $layout = (isset($display->layout)) ? $display->layout : false;

        /* layout e.g column_one_fluid, column_three_fluid etc. */
        $fluid   =  $layout ? preg_match("/\s*.+_fluid$/", $layout) : false;

        /* layout e.g column_one_landing, column_three_landing_fluid etc. */
        $landing =  $layout ? preg_match("/\s*.+_landing$|\s*.+_landing_fluid$/", $layout) : false;

        $variables['page_fluid'] = ($fluid) ? true : false;
        $variables['page_landing'] = ($landing) ? true : false;

        if($fluid) {
             $variables['theme_hook_suggestions'][] = 'page__fluid';
        }
        if($landing) {
            $variables['theme_hook_suggestions'][] = 'page__landing';
        }

    }

```

# Answer
If you don't already have one create a yourtheme.layouts.yml file in your theme folder. There you will define the regions, preview icons, and labels.

```
custom_2col_brick:
  label: Two Column Brick
  category: My Custom Layouts
  template: layouts/custom_2col_brick
  icon: layouts/custom_2col_brick.png
  regions:
    left:
      label: Left
    right:
      label: Right
    footer:
      label: Footer
custom_1col_landing:
  label: One Column Landing
  category: My Custom Layouts
  template: layouts/custom_1col_landing
  icon: layouts/custom_1col_landing.png
  regions:
    main:
      label: Main Region
    footer:
      label: Footer

```

Now you can create your page\__custom\_2col\_brick.html.twig and page\__custom\_1col\_landing.html.twig files in your layouts folder. Inside there you can define your template. For example custom\_1col\_landing.html.twig could contain

```
<div class="one-column-layout">
    <div class="row main">
        {{ content.main }}
    </div>
    <div class="row expanded one-column-footer">
        {{ content.footer }}
    </div>
</div>

```

Once finished you should have the following files. (The preview icons are optional)

```
/yourtheme/yourtheme.layouts.yml
/yourtheme/layouts/custom_2col_brick.html.twig
/yourtheme/layouts/custom_1col_landing.twig

```
> 1 votes

# Answer
Use hook\_theme\_suggestions\_HOOK\_alter() and \Drupal::routeMatch()-\>getRouteObject().

```
/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function mytheme_theme_suggestions_page_alter(&$suggestions, &$vars) {
  $request = \Drupal::routeMatch()->getRouteObject();
  if ($request->getDefault('_entity_view') === 'page_manager_page_variant') {
    $page_name = $request->getDefault('page_manager_page');
    $page_variant = $request->getDefault('page_manager_page_variant');
    $suggestions[] = 'page__page_manager';
    $suggestions[] = 'page__page_manager__' . $page_name;
    $suggestions[] = 'page__page_manager__' . $page_name . '__' . $page_variant;
  }
}

```
> 1 votes

# Answer
Expanding upon gambry's answer:

```
/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function mytheme_theme_suggestions_page_alter(&$suggestions, &$vars) {
    $request = \Drupal::routeMatch()->getRouteObject();
    if ($request->getDefault('_entity_view') === 'page_manager_page_variant') {
        $page_variant = $request->getDefault('page_manager_page_variant');
        $name = 'page_manager.page_variant.' . $page_variant;
        $config = \Drupal::configFactory()->getEditable($name);
        if ($config->get('variant') === 'panels_variant') {
            $layout_id = $config->get('variant_settings.layout');
            $suggestions[] = 'page__page-manager';
            $suggestions[] = 'page__page-manager__' . $layout_id;
        }
    }
}

```

This should give you the layout id. In my case, i have a panel using the default 1 column layout, and I can use the following twig templates:

* page--page-manager--layout-onecol.html.twig
* page--page-manager.html.twig
* page.html.twig

I agree with Matt that for the meat of the page you should use the panel layout's twig files (the yourtheme.layouts.yml method). Only use the above if you're trying to override the overall page template based on the panel layout.
> 0 votes

---
Tags: theming, 8, panels
---


# Question
Title: How to handle caching on a Drupal 8 custom Views access plugin that checks a User's Profile's field value
I have a custom Views access plugin that check access against a value in the current User's Profile (entity) field value.

The plugin works but if I change the profile field value the access does not check again until the cache is cleared. I know this is an issue with setting up the cache tags/contexts but I cannot not figure out what is needed so that the cache is cleared when the user profile is updated.

Right now I'm not using any cache tags/contexts in my View access plug and I've tried various combinations without luck. Help!

Current cache functions:

```
public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return ['user'];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    $profile = \Drupal::entityManager()->getStorage('profile')->loadByUser(user_load(\Drupal::currentUser()->id()), 'employee');
return $profile->getCacheTags();
  }

```

# Answer
> 4 votes
A Views access plugin implements CacheableDependencyInterface. So you probably need to set a tag and a context for the current user in these methods:

```
  /**
   * {@inheritdoc}
   */
  public function getCacheMaxAge() {
    return Cache::PERMANENT;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return ['user'];
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheTags() {
    return ['user:' . \Drupal::currentUser()->id()];
  }

```

---
Tags: 8, views
---


# Question
Title: How do I pass variables to a view builder's renderer?
I'm creating a module that will render a few nodes before getting back the result and print it as PDF. (I can't use wkhtmltopdf; I wish I could.)

So far, I managed to make my controller/action use the template I wanted, and anything I write in the template file is showed with `die($html)`. However, I can't find any example of how to pass variables to the view; I tried a few things, but I got nothing, excepted 500 errors.

This is the code I am using.

```
public function nodeAction(NodeInterface $node) {
  // Here, I define a variable named $responses that contains a lot of datas as arrays
  $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  $build = $view_builder->view($node, 'cnas_pdf');
  $html = \Drupal::service('renderer')->renderPlain($build, ['var' => $response]);

  // No error in this configuration, but "var" is nowhere to be found
  die($html);
}

```

# Answer
This is not possible to add parameters to renderPlain(). What you can do depends. If you want to use a variable inside of the node, then do this in a node preprocess hook. But more likely you want to add additional elements to the build array before you render it, for example:

```
$build = [];
$build['top'] = ['#markup' => 'abc'];
$build['node'] = $view_builder->view($node, 'cnas_pdf');
$build['footer'] = ['#markup' => 'xyz'];

```
> 3 votes

# Answer
This might be a slightly different scenario than your original question, but I stumbled across while searching for ways to add custom variables to an entity's template at the time that I build it with the ViewBuilder, versus altering existing variables in a preprocess. Hopefully this should be helpful.

The ViewBuilder's `view()` method returns a render array, so you can use that to pass your custom variables to the template.

```
public function nodeAction(NodeInterface $node) {
  // Here, I define a variable named $responses that contains a lot of datas as arrays
  $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  $build = $view_builder->view($node, 'cnas_pdf');
  $build['#my_response'] = $response;
  $html = \Drupal::service('renderer')->renderPlain($build);

  // No error in this configuration, but "var" is nowhere to be found
  die($html);
}

```

After modifying the `$build` to include the new array key, you should have access to it in your node's template, such as with `{{ elements['#my_response'] }}` in this case. If you wanted to make this a bit cleaner in a preprocess, you could then do something like:

```
/**
 * Implements theme_preprocess_node().
 */
function mytheme_preprocess_node(&$variables) {
  if (isset($variables['elements']['#my_response'])) {
    $variables['my_response'] = $variables['elements']['#my_response'];
  }
}

```

You would then be able to access it in your template directly with `{{ my_response }}`.
> 4 votes

---
Tags: theming, 8
---


# Question
Title: How To Show Node Comment Count in node.tpl?
I have had the bright idea of changing my user permissions so as guests cannot see the comments on a node. I have no problems with Views around my site, as they can clearly see there are comments on nodes, and they will be more inclined to register. The problem seems to be when they arrive on my site directly to a node, they don't see any comment, and think "that's a bit crap; let's go."

Is there a way I could show the amount of comments below a node?

# Answer
I recommend you use template\_preprocess\_node().
This is a basic example for D8

```
function YOUR_THEME_preprocess_node(&$variables) {
  $variables['comment_count'] = $variables['node']->get('YOUR_COMMENT_FIELD')->comment_count;
}

```

And then you can use it in your `node.html.twig` file like so:

```
{{ comment_count }}

```

A basic example in D6 is below, you can customize it to your liking. In your template.php file located in your theme directory, add something along the lines of (replacing YOURTHEME with the name of your theme):

```
function YOURTHEME_preprocess_node(&$variables) {
  $nid = $variables['node']->nid;
  $variables['num_comments'] = db_result(db_query('SELECT COUNT(cid) AS count FROM {comments} WHERE nid = %d', $nid)) . ' comment(s) on this node';
}

```

and save the file. Now in node.tpl.php (or any equivalent template, node-mycontenttype.tpl.php, etc) simply add:

`<?php print $num_comments; ?>`

Wherever you would like the comment count to be located and save. **Clear the cache** and then view your changes.
> 10 votes

# Answer
You can use `$comment_count` in node.tpl.php.

> `$type`: Node type, i.e. story, page, blog, etc.
> `$comment_count`: Number of comments attached to the node.
> 12 votes

# Answer
Update, for Drupal 7 your query on template.php should look like:

```
$vars['num_comments'] = db_query("SELECT COUNT(cid) AS count FROM {comment} WHERE nid =:nid",array(":nid"=>$vars['nid']))->fetchField();

```
> 4 votes

# Answer
In Drupal 8 use this directly in your node template:

```
{{ node.comment.comment_count }}

```

Note that for it to work you need to have the default comment field in your node which is always named comment.
> 1 votes

# Answer
For Drupal 8:

```
function YOURTHEME_preprocess_node(&$variables) {
  $nid = $variables['node']->nid->value;
  $num_comment = db_query('SELECT comment_count FROM {comment_entity_statistics} WHERE entity_id = ' . $nid)->fetchAssoc();
  $variables['comment_count'] = $num_comment['comment_count'];
}

```

Now in page.html.twig:

```
{{ comment_count }}

```

Clear the cache and then view your changes.
> 0 votes

---
Tags: theming, comments
---


# Question
Title: is there a way to hide a "custom field" in edit mode Drupal 8?
I have a form with 5 custom fields. I would like to hide a couple of fields based on the view mode **in the back-end while the user is editing the form.** Right now you can easily hide the field in the front end, but i am looking for way to not confuse the editors and hide the form fields while they are making changes. Disable fields still show up in the back-end.

My goal is simple: if your view mode has the field disable it should not show up in the back-end and in the front end.

is there a setting or a hook that can allow me to accomplish that.

# Answer
> 1 votes
Making this based if it's printed on a view mode, makes things quite complex. You'll have to write a custom module.

Try using the Fields Permissions which is based on Roles. So just check mark the Roles that should be able to see the field in the front.

---
Tags: hooks, display-suite
---


# Question
Title: Apply custom date formats to reporting for specific webforms and fields
I realize that similar questions have been asked multiple times, but find that either the answers aren't what I am looking for or the specifics of the question aren't the same.

I want to create a custom date format for two different date fields within a specific Webform (not globally). The first date field is the submission date and the second is a date of birth field that we added.

I have created the desired custom date formats in `admin/config/regional/date-time/formats` let's call them A and B. Then I created custom date types using those formats in `admin/config/regional/date-time`.

I cannot find where to apply date type "A" to submission dates for the webform and I cannot find where to apply date type "B" to my custom date of birth field within the webform.

Submission Date:

Format A: `Y-m-d - H:i` This appears to be an internal field, as it doesn't show up in my list of webform fields. I checked form settings and in advanced form settings as well as in form components.

Date of Birth Date:

Format B: `Y-m-d` This is a custom field. When I click "edit" for this field, I don't see where to specify how the date format will be recorded.

Furthermore, it isn't important to me how these dates look when viewed on the survey or on the screen but they need to be recorded so that they are in the downloaded data in the specified format.

# Answer
It seems that the only way to make this happen was to reset the system's Short Date Format to my custom format A. Thankfully, the webform custom DOB field uses a similar format (the same thing but without the hour and minutes.)

If anyone knows a better way where I could have done this on a "per form" and "per field" basis, please add your answer as the one I am providing now isn't really what I was looking for.
> 1 votes

# Answer
Just create custom date formate it would be like this

```
if(isset($record['doc_date']))
{
$date = explode(" ",$record['doc_date']);
$d_date = date("d-m-Y",strtotime($date[0]));
}

```

and create date field

```
$form['doc_date'] = array(
    '#type' => 'date',
    '#required' => TRUE,
    '#date_date_format' => 'd-m-Y',
    '#default_value' => (isset($record['doc_date']) && $_GET['num']) ? $d_date:'',

```

i hope it would work
> 0 votes

---
Tags: 7, webforms, datetime
---


title: Varnish and page cache

text:
# Question
Title: Varnish and page cache
I have a question about using Varnish along with the Drupal page cache. I was wondering if using both of them is a bit redundant, since Varnish already caches pages for anonymous users?

Currently I have page cache off, page cache max-age zero and cache lifetime set to 10 minutes.

Am I reasoning this right or am I just missing something obvious?

Thanks.

# Answer
As answered by @dicix, Drupal will not return the correct `Cache-Control` headers to Varnish without "Page Cache" being enabled in the Drupal Performance configuration.

The problem I ran into with having both the Drupal Page Cache and Varnish at the same time is that it potentially increases the delay before stale content is refreshed to a maximum of both TTLs. For example, having a max-age of 5min could result in the stale content sticking around and being served for up to 10 minutes (or 15 minutes if Varnish doesn't reset the cache-control header given to the browser to something less).

My solution was to set "Cache pages for anonymous users" to be on in the Drupal Performance settings with a reasonable "Expiration of cached pages" of 5min. I then added the following to my `settings.php` to prevent Drupal from actually caching any page content:

```
// Use the fake cache for pages since we are caching anonymous HTML with Varnish
if (!class_exists('DrupalFakeCache')) {
  $conf['cache_backends'][] = 'includes/cache-install.inc';
}
$conf['cache_class_cache_page'] = 'DrupalFakeCache';

```

The DrupalFakeCache just provides stubs that don't store anything or return anything.

Reference: Suppress caching (for development) or to use an external page cache
> 4 votes

# Answer
Good point Jimajamma, but my question was different.

Apparently I got the answer for this, if case someone else is interested.

Varnish will not cache pages unless both "Page Cache" is turned on and a "Page cache max-age" is set. Drupal will not set the correct caching headers if "Page Cache" is not enabled. "Cache lifetime" and "Block Cache" does not affect Varnish caching.

Basically Drupal sets the cache-control headers. If Drupal is told not to cache pages, then it tells everything else (Varnish, Akamai, etc) not to cache either.

Varnish can be configured to bypass this feature, but it doesn't do it by default.

Hope this helps someone.
> 3 votes

# Answer
A number of sites are set up with this double caching, especially if a Varnish server is front ending/edging multiple sites AND the cache lifetime on the Varnish end is less than the cache lifetime on the drupal end.

Example.

You set up files to have a cache lifetime of 10 minutes on your drupal site, but you set up Varnish to have a cache lifetime of 5 minutes.

As anonymous users hit your website, Varnish serves all pages up to that 5 minute mark, but then allows drupal to come into play for any not there, or that have expired.

If expired or otherwise not in Varnish, and they are less than 10 minutes old, drupal's cache serves them up quickly and Varnish then does the same for the next 5 minutes.

While this might seem odd, it allows Varnish to keep a "hotter" cache, and since its in memory, you really want it only to keep stuff that is being hit often, so by keeping it's cache lifetime lower, odd ball pages aren't kept cluttering it up (especially if as mentioned it is serving multiple sites) yet are somewhat readily available on the drupal end in its most probably larger disk based cache.
> 1 votes

# Answer
You need to enable the page cache, so Drupal sets the correct caching headers.

But this doesn't mean Drupal will store the page in its own cache. If you use the Varnish module, you will have this in your settings.php:

```
$conf['cache_class_cache_page'] = 'VarnishCache';

```

which prevents the page from being written to Drupal's default page cache, the database.
> 1 votes

---
Tags: caching, proxies
---


# Question
Title: View Group By field with mult-value field
I have a field that contains multiple boolean values ( similar to a tag or taxonomy term) which indicates status. So the field is like this.

application="received, data complete, references, financials," I'd like to create a tabular report grouped like this:

Received:
Item A Item C

Data Complete:
Item A Item B

References:
Item A Item B

The problem is that grouping on the field is like this: Received, Data Complete, References:
Item A

Data Complete, References:
Item B

Received:
Item B

So I need to break up the field in views. I realize I can create a view in a view or view field, but wondering if there is anything more simple/elegant.

# Answer
You can also uncheck the box "display all values in the same row" under the multiple field settings menu in the configure field settings. Doing this "denormalizes" the data. This works for both content and taxonomy terms - in my case accessed via entity reference. This way you can make the best choice between content and taxonomy in your design.
> 1 votes

# Answer
Your premises are not quite clear, but assuming that you are in a Drupal 7/Views 3 environment and that your status field leverages Drupal Taxonomy, you could achieve it in this way:

1. Create a new view.
2. Choose *Taxonomy terms*—not *Content*—from the dropdown list after "Show" and select your vocabulary as type.
3. Your new view will contain *Taxonomy term: Name* as the only field. To get the titles of the nodes tagged with the terms of your vocabulary, first add the relationship *Taxonomy term: Content using {name\_of\_your\_vocabulary}*.
4. Then add the field *Content: Title* and apply the previously created relationship.
5. Now exclude the term name field from display and select it as Grouping field in the Format settings.

This method will provide exactly the desired data structure:

**data complete**

Item A
Item B

**received**

Item A
Item C

**references**

Item A
Item B

You might want to adjust the order of the terms by adding term name/weight or other sorting criteria.

=======================

EDIT: If your field is not taxonomy-based but, say, a list field or any other field type capable of containing multiple values, you could get the same result along these lines:

* Create a view on nodes, not terms.
* Add node title and status (or whatever your field is called like) as fields.
* **Uncheck** the "Display all values in the same row" feature in the status field's Multiple field settings.
* Exclude status from display and select it as grouping field.
* Add 'status: is not empty' as filter criterion to exclude irrelevant nodes.
* Adjust filter and sorting criteria to your needs.
> 0 votes

---
Tags: views
---


# Question
Title: Why can't I uncheck "Create new revision" on the content type edit page?
On Drupal 8, I created a new content type, **MyContentType**, and accepted all the defaults.

I noticed that *Create new revision* under **Publishing options** was checked but slightly grayed out and I could not adjust the value, even though I was logged in as user 1:

I don't know why I can't uncheck it, but this is fine because I always want to save a new revision every time the node is saved.

However, to test this, I then created a new node of **MyContentType** and saved it. Then I edited the saved node-- and the *Create new revision* checkbox is unchecked!

So *Create new revision* is permanently enabled on the content type edit page, but on the actual edit pages for that content type, the revision box is not checked by default.

What is causing this bizarre behavior?

In Drupal 8.2, create new revision became checked by default, but it says nothing about making it "mandatory by default".

# Answer
> 8 votes
The problem was the Content Moderation module (Drupal 8.4). I guess I have to take the *experimental* warning seriously.

When **Content Moderation** module is enabled, you can't change the "create new revision" status for any content type.

However, content types not subject to content moderation will not have the "Create new revision" box checked on the node edit page if the box was not checked before Content Moderation was enabled-- or if the content type was created while Content Moderation was enabled.

This can be confirmed by checking the config for the content type that has been exported by drush, which shows `new_revision: false`. This is most likely a bug so I'm off to file an issue.

---
Tags: 8, nodes
---