Drupal Howtos

A how-to is a short description of how to accomplish a specific task. This is a compilation of Drupal related howto's which I provided to friends or which I applied myself. Targeting the Drupal beginner they provide simple and detailed step-by-step descriptions with pictures.

Drupal 7: How to override the page.tpl for specific content types?

A common override that is not included in the default list is the page.tpl.php override based on the content type being displayed. There is a node.tpl.php override based on the same condition which leads to confusion as to where the page override exists. On top of that, themes like Zen add this type of override to the Template Suggestions, which leads those using Zen to believe that this is part of the default list. Check the theme documentation to see if this override has been added to the Template Suggestions by the theme. If it hasn’t, you need to add it manually.

Drupal PHP

How to change the language attribute href (html lang="xx") without extra installations

Sometimes it is convenient to change the language definition of a website without the installation/configuration of extra modules/languages. For example if you create a copy of a very simple informational website and you want to change its language without touching language settings/modules.

The language attributes typically can be found in the following file:


$variables['html_attributes']['lang'] = $language_interface->getId();


Troubleshooting: Impossible to save settings for a new Multimedia asset field

Using 7.x-2.0-alpha4 or media 7.x-2.0-alpha3 of the Drupal media module, you might get the following error while saving the settings for a new multimedia asset field.

"Notice: Undefined index: settings in media_field_instance_validate() (line 382 of [...]\sites\all\modules\media\media.module). The upload destination must be one of the allowed schemes."

Whether you check upload or any other option has no influence. To solve the problem you have to options.

How to choose, download and install additional themes?

Themes allow you to change the look and feel of your website. This howto will give you step-by-step instructions how to choose, download and install a theme.

List of Drupal themes

"From address" doesn't work in Forward Module. How to solve the issue?

If the "From address" is left blank the site email address is used instead of the address entered by the user. This howto shows you how to solve the issue quickly.

Composer require error: can't delete default.services.yml

1. This command will fix it temporarily:

chmod u+w web/sites/default

2. But Drupal will harden permission again soon. To turn it off add this to settings.php:

$settings['skip_permissions_hardening'] = TRUE;

Note: 1. seems to work, 2. not

Source: https://drupal.stackexchange.com/questions/290296/composer-require-error...

Install Drush on shared hosting

Updated for PHP 7.2:

cd $HOME
ln -s `which php72` ~/bin/php
export PATH=$HOME/bin:$PATH
curl -sS https://getcomposer.org/installer | php72
echo -e "\n# Composer\nalias composer=\"php72 \$HOME/bin/composer.phar\"" >> $HOME/.bash_profile
source $HOME/.bash_profile

Example from Webfaction Hosting.

Source: https://gist.github.com/matthewspencer/8969473

How to modify Twitter Bootstrap collapse plugin to keep accordions open

Since the question didn't refer to a specific version of Bootstrap, here's a bootstrap 4 solution: remove the data-parent="#accordion" from the tags with the data-toggle="collapse" attribute. It's the example taken from the Collapse documentation with the data-parent=#accordion" bit taken out.

bootply: https://www.bootply.com/3wV4WbzBtT


Drupal themes to be compared