Node content type object in Drupal 8

When obtaining the node types on a given Drupal site in Drupal 7 we use:

$types = node_get_types();

And the content type machine name is available from:

$names = array();
foreach ($types as $type) {
  $names[] = $type->type;

In Drupal 8 we use the following:

use Drupal\node\Entity\NodeType;

$types = NodeType::loadMultiple();
$names = array();
foreach ($types as $type) {
  $names[] = $type->id();

Kent Shelley Mon, 07/11/2016 - 20:45
Installing Varnish 4.x on Apache Debian 8 server (Jessie) with Drupal 8

Varnish is a very fast caching mechanism for web applications but it is not always easy to install.  In the latest version there are a number of changes pertinent to Debian servers.

The following assumes you are working as root.  If not, then you need to add sudo to the front of all commands.

Installing Varnish on the server

At the command line:

Kent Shelley Sat, 07/02/2016 - 03:04
Create a Formatter Plugin to provide active trail links in Drupal 8 Views list

In this example I show how to create a formatter plugin to provide an active trail class to highlight the link of the current page in a Views list.  This behaviour is native to Drupal menus and I could have created a menu but that would not be dynamic and anyway, I wanted to see what is involved in applying active trail classes to a Views list.

Kent Shelley Tue, 06/28/2016 - 08:17

A CTools modal confirm form in Drupal 7 with custom window size

This example uses the ajax callback on a form to provide a simple modal confirmation step using a custom sized window.

Here is our form.  We include the required ctools modal scripts and add our own script to control the confirm functionality.  The modal control is done by the action on the drupal js settings for 'CToolsModal'

function MYMODULE_form($form, $form_state, $items, $entity, $field) {

How to suppress display of extra field in a Drupal 7 field with unlimited values

By default the Field API in Drupal 7 displays an extra empty field in a field with multiple values when editing the form.  There is no setting for suppressing this display at in the Drupal backend and so it has to be done with some scripts.  The following example is for a custom field made using hook_field_widget_info() and is implemented in the widget form function.  Here is a screenshot of the custom field with the extra field displayed:

Drupal Migration version 6 to version 8

In the process of upgrading sites from Drupal 6 to Drupal 8 using the information provided by Drupal Documentation, using the drush implementation.

I have a multisite setup in Drupal 8 and found that drush reads the current site according to the values found in /sites/default/settings.php so for each site I upgraded I had to change the database settings in that file to suit the site I was working on.

Using Colorbox Inline with Views to Display image AND content in a Colorbox

For this implementation you will need to install Colorbox and Colorbox Inline module on a Drupal 8.1 site or higher.  For this exercise I wanted to create the portfolio page on this site, so that when I click on an image on the page I get a lightbox with the image, title (with link) and description of the item.  First create a block View with the image and the desired fields.  If you are displaying more than one image, as I am, using masonry, then you will need to get the ID field (hidden) to use as an identifier.  I have also obtained the image field twice.

Kent Shelley Mon, 06/13/2016 - 01:00

Using Ansible - Install Firewall

We should have done this earlier but now that the server is running we need to ensure some level of security so we install a firewall.  The original script we used to install LAMP did not provide much security and so we will insert the new ansible tasks into the ansible_lamp playbook so that next time we use it, we get the firewall up as soon as apache is enabled.