Drupal 8

Solution to Drupal 8 Redirect module causes infinite loop (ERR_TOO_MANY_REDIRECTS) in all the URLs except front page for anonymous user

When I tried to install Drupal 8 Varbase distribution and visited its sub pages as anonymous user (like Login page https://www.webfoobar.com/user/login) I get this error message in my browser:

This page isn’t working

www.webfoobar.com redirected you too many times.

Try clearing your cookies.

ERR_TOO_MANY_REDIRECTS

... and the URL changed to:

Solution to so many redirects error executing independent PHP script in a Drupal 8 site running under nginx

The issue is when executing a standalone PHP script in a Drupal 8 site running under nginx gets "The page isn't redirecting properly" error in Firefox and getting this error in Chrome: "This page isn't working [domain] redirected you too many times." but the PHP scripts that executes under Drupal 8 bootstrap don't get this issue. The bug must be on nginx webserver configuration. Investigating the nginx configuration file php_pass.conf that handles my Drupal 8 site PHP scripts:

Smart IP Drupal 8 settings explained

The following is the explanation of each Smart IP Drupal 8 settings.

Database Update Status

This Smart IP section setting will only appear if your Data Source is either IP2Location binary database or MaxMind GeoIP2 binary database. It display the status of database update process from manually executed or automatically during cron run. If the database update failed, you can manually force the database update by clicking the "Update database now" button.

How to setup a working Responsive Image in Drupal 8

Responsive Image module is a core module in Drupal 8 and this guide will show setting up this module with working example.

Steps:

  1. Enable the Responsive Image module at http://www.yoursite.com/admin/modules.

  2. We can use existing Breakpoint group but in this guide we will create our own Breakpoint group. It can be created as module or as theme and we will create this as module. Inside /modules folder of your Drupal 8 site, create a folder labelled as "site_optimization".

Adding external javascript library available to all pages with query string value came from PHP in Drupal 8

In Drupal 7, adding external javascript library available to all pages with query string value came either from PHP computed value or from database this can be done by:

  
/**
 * Implements hook_init()
 */
function mymodule_init() {
  drupal_add_js('//maps.googleapis.com/maps/api/js?key=' . variable_get('mymodule_google_map_api_key', NULL), 'external');
}
  

For Drupal 8 this is possible by:

Installing geoip2 required library for Smart IP's data source MaxMind GeoIP2 binary database

The MaxMind GeoIP2 binary database is a custom binary format and there are two available APIs that read this binary database: MaxMind DB Reader PHP API which includes an optional C extension that you may install to improve binary database lookup performance and the default is GeoIP2 PHP API. We will discuss how to install these two APIs in your system.

Passing data from PHP to javascript variable available to all pages in Drupal 8

Most of us pass data from PHP to javascript variable available to all pages in Drupal 7 is by:

  
/**
 * Implements hook_init()
 */
function mymodule_init() {
  $computed_data = mymodule_get_data();
  drupal_add_js(array('mymodule_computed_data' => $computed_data), 'setting');
}
  

We can access this data in javascript by:

Setup Drupal 8 module using Composer

Drupal uses an externally-maintained repository the https://packagist.drupal-composer.org but this repo is scheduled to be deprecated in January 2017 by then we will be using https://packages.drupal.org/8 repo URL.

It is assumed that composer is already installed in your system. Make sure your composer version is 1.0.0 or higher, to check execute:

  
composer -V
  

If it is lower than version 1.0.0, update it by:

  
composer self-update
  

Change directory to your Drupal root path.

Installing ip2location-php required library for Smart IP's data source IP2Location binary database

Using Smart IP's data source IP2Location binary database requires ip2location/ip2location-php library which contains API that reads its database file. This article will show how to setup this API using composer.

The following procedures are tested on my Linode server running Centos 7 64-bit Linux distribution.

  1. First we will install composer: