Drupal

Drupal Custom Contextual Filter

A custom contextual filter for Views in Drupal 8 is demonstrated using the Data project. Only a small amount of code is needed for the custom filter.

Set up Drupal

Begin by setting up Drupal and installing the Schema and Data projects.

composer create-project drupal-composer/drupal-project:8.x-dev contextual --no-interaction

Create a database and visit the website to install it. Now install a couple of contributed projects.

Decoupled Drupal, GraphQL and React

Decoupled Drupal is gaining increased interest.  Decoupling refers to using Javascript for the front end of the website and Drupal for the back end content.  Many of the tutorials leave out critical information and even quite recent tutorials are already out of date because the software is changing so quickly.  Developing a production website under these conditions is still risky but has intriguing possibilities.  Javascript avoids page reloads and promises increased speed and separation of the display from the data.  But building a display yourself loses things lik

Migration in Drupal - Part 2

Part 1 looked at how to put the source database credentials in settings.php.  Part 2 looks at how to specify the source website root so that files are properly transferred.  After the fix for the database settings in part 1 the command for configuring the migration is

drush migrate-upgrade --legacy-root=http://mydrupal7site.com --configure-only

The import of the files is done by running

Xdebug with Vim for Docker for Mac with Ubuntu 16.04

Integrated Development Environments (IDEs) are nice for debugging problems but with Docker containers they have to be set up to work remotely. Vim may not be as nice an interface but has an advantage of being able to run in the container making it easier to get set up and running quickly. This is especially true for new releases where there is not much information yet on configuration.

Web development with Docker and Drupal on OS X

Docker has just been released for Mac OS X and it takes a different approach of using containers.  It claims to be faster and quicker to set up then alternatives such as virtual machines.  I will look at using Docker to set up a basic local development environment for a Drupal 8 website on Ubuntu 16.04.  I will be using PHP 7.0 and MariaDB.  This is done for an actual website and some problems are encountered which will demonstrate how to debug and the tools that can be used to solve issues.

Where has basePath gone in Drupal 8?

Javascript code in Drupal 7 used drupal_add_js() to attach Javascript code to a webpage.  The Javascript code then used Drupal.settings.basePath to prepend the path to the Drupal installation.  For Drupal installed in the root directory, Drupal.settings.basePath is just the string '/' but if Drupal is installed in a subdirectory then this is necessary for the Javascript code to continue to work.  The php part is

drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');

and the Javascript part is

Create a node programmatically in Drupal 8

Many of the changes from Drupal 7 to Drupal 8 involve the use of object oriented code. One particular change is to move away from code specific to nodes to writing the code for entities and then overriding or extending it where necessary for nodes. Conceptually, this results in being able to use much of the same code for other entities including custom entities.