Drupal Tips and Tricks

The installation, configuration and the work with Drupal obviously brings some challenges. Within this section you find some Tips and Tricks which shall help you to make your work easier.

Trobleshooting computed field with Drupal 8 (Drupal core 8.3.2; May 2017)

  • 8.x-1.0-alpha1 does not work with Drupal core 8.3.2 (you'll get unexpected errors) >> Choose 8.x-2.x-dev
  • Computed fields don't display on content types which existed prior the module is installed >> Create a new content type and everything works smoothly

Important: The field only updates when the node is saved (Cron, clear cache and similar not enough)

Drupal Computed field

Drupal Rooms Availablity Search Block - Ajax breaks "Book this Room" link

Ajax overrides form action="/node-url" with action="/views/ajax"

Workaround with Drupal's hook_form_alter() for views module. See similar problem with solution here: https://www.drupal.org/node/1294164#27

The hook_form_alter() basics can be found here: http://websmiths.co/blog/very-introduction-drupals-hookformalter

Offsetting an html anchor to adjust for fixed header

You could just use CSS without any javascript.

Give your anchor a class:

<a class="anchor" id="top"></a>

You can then position the anchor an offset higher or lower than where it actually appears on the page, by making it a block element and relatively positioning it. -250px will position the anchor up 250px

a.anchor {
display: block;
position: relative;
top: -250px;
visibility: hidden;
}

The best free stock image websites for your Drupal project (2018)

With human brains processing images much faster than text, good photos are vital for grabbing attention and getting messages across. Unfortunately, we’ve grown accustomed to seeing cheesy stock images of people in suits shaking hands. These stock photos not only lack quality, they also cost a lot of money. Thankfully, there’s been a growing number of websites with beautiful free stock photography popping up all over the web. We selected the best free stock image websites available end of 2018.

The best free stock images websites for your Drupal project

Grayscale and Black & White Google Maps (applicable to Drupal Google map modules)

If you search on the web on how to to get a black and white google maps iframe it's quite surprising how hard it is to find a good answer.

So that's why I'm Re-sharing this tip.

.map {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
}

You can apply this css code to any div which holds the Google map, so also to any such div from a Drupal Google map module.

Grayscale and Black & White Google Maps

"The website encountered an unexpected error. Please try again later." (Drupal 8)

You might get "The website encountered an unexpected error. Please try again later." after the installation or uninstallation of a module, when you login with the admin user or in general. Possible solutions:
  • run update.php
  • move the module installed/uninstalled outside the Drupal installation
  • Clear cache within the database by emptying all cache tables

Use the Drupal module File Entity (fieldable files) to add files over the web interface

File Entity (or fieldable files) is an easy solution allowing you to add files over the web interface without FTP (if admin/content/file is missing, install the File Entity module. File entity provides interfaces for managing files. It also extends the core file entity, allowing files to be fieldable, grouped into types, viewed (using display modes) and formatted using field formatters. File entity integrates with a number of modules, exposing files to Views, Entity API, Token and more.
Drupal module File Entity (fieldable files)

Pages

Drupal themes to be compared