Skip to main content

Working with Drupal 8

Drupal 8 saw a dramatic change from previous releases of Drupal. Amongst these changes is a big step towards using an object oriented approach built around the Symfony 3 framework instead of using hooks.

Other changes include a complete rethinking of how themes work with a change to use the TWIG theme engine rather than PHP template. Take a look at some of our Drupal 8 posts below...

Read some of our articles about Drupal 8

Dependency Injection - how to access services in controllers

Jo Fitzgerald
Jo Fitzgerald
16th Aug 2016

If you are trying to get to grips with Dependency Injection in Drupal 8 then here is a walk-through of how I applied it in one of my Drupal 8 test projects.

I have a project I have been using to investigate Drupal 8 since alpha10 which has been invaluable in my learning process. But as a result, some of my code is over 2 years old and written when I barely had a grasp of Drupal 8 concepts.

In the past week a very old @todo jumped out to me:


// @todo Find a way to get a...
Read more

Drupal 8 Config Management - how should I add config to a D8 site?

Jo Fitzgerald
Jo Fitzgerald
9th Aug 2016

For me this is the biggest unanswered question hanging over my development of Drupal 8 websites: How should I add config to a Drupal 8 site?

This article will provide plenty of options, but unfortunately no definitive answer.

Read more

Drupal 8 Namespaces - class aliasing

Jo Fitzgerald
Jo Fitzgerald
2nd Aug 2016

Class Aliasing is the simple, but very useful solution to the problem of needing to use two classes (from different namespaces) with the same name.

Read more

How to write a PHPUnit functional test for Drupal 8

Jo Fitzgerald
Jo Fitzgerald
21st Jun 2016

This article will talk you through the steps to follow to write a simple PHPUnit functional (Kernel) test for Drupal 8.

I have been doing a lot of work on Drupal 8 migrations for the past few months so that will be the focus of the test.

Read more

Drupal 8 Event Subscribers - the successor to alter hooks

Jo Fitzgerald
Jo Fitzgerald
14th Jun 2016

In Drupal 7 if you wanted to tweak the functionality of an existing function then an alter hook was your best friend, but in Drupal 8 it's "all change!"

With the introduction of Symfony, your new BFF is an Event Subscriber. Alter hooks still exist, but it is recommended that we all move towards Events to fall in line with Symfony.

If you are interested in the comparison between alter hooks and events then I recommend this article from PreviousNext.

Introduction

In just 4 simple steps, this article will talk you through the process of writing a custom Event...

Read more

Checking if the current page is the homepage in Drupal 8 - not using drupal_is_front_page

10th May 2016

We will keep this one short and sweet. There is quite a bit of documentation pointing to the fact that drupal_is_front_page() still exists in Drupal 8 ... it doesn't!

Panic not. The solution is nice and easy, the following snippet will act as a drop in replacement for drupal_is_front_page() - simply returning TRUE or FALSE.


\Drupal::service('path.matcher')->isFrontPage();

Read more

Saving the web with responsible websites

22nd Jul 2015

I recently read the trending article The Web We Have to Save, by blogger Hossein Derakhshan ('Hoder'), who had been imprisoned in Iran for six years. In the article, he talks about how the internet had changed over that time. Quality can be drowned out; what is important is diluted in amongst the trivial.

Personally, I believe any expression of culture will reflect the society it flows from. The internet is a global society, so incorporates so many different aspects of humanity - different, good, and bad.
What does the internet say about our global society? I believe that we should all take responsibility to some extent -- especially those of us in the business of websites and content on the internet! Can we contribute to a more responsible internet? Are we equipped to do so?

Read more

Drupal 8: Creating a custom field - Part 3: Field formatter

Jo Fitzgerald
Jo Fitzgerald
11th Feb 2014

This is part 3 in my series of articles about creating a custom field. I recommend reading Part 1: Field type and Part 2: Field widget first, if you have not done so already.

After creating the field type and field widget it is now time to complete the set by creating the field formatter.

##a) Create the file
The field type must be located as follows:

<module_name>/lib/Drupal/<module_name>/Plugin/field/formatter/<field_formatter_name>.php
N.B. The field formatter name should be in CamelCase.

##b) Add Contains, namespace and use
In the newly created field type file add a brief comment to explain...</field_formatter_name></module_name></module_name>

Read more

Drupal 8: Creating a custom field - Part 2: Field drupal widget

Jo Fitzgerald
Jo Fitzgerald
4th Feb 2014

This is part 2 in my series of articles about Drupal widgets, and specifically creating a custom field. I recommend reading Part 1: Field type first, if you have not done so already.

After creating the field type it is now time to create the field widget.

##a) Create the file
The field widget must be located as follows:

<module_name>/lib/Drupal/<module_name>/Plugin/field/widget/<field_widget_name>.php</field_widget_name></module_name></module_name>

N.B. The field widget name should be in CamelCase.

##b) Add Contains, namespace and use
In the newly created field type file add a brief comment to explain what it consists of:


/**
 * @file
 *...
Read more

Drupal 8: Creating a custom field - Using a custom field

Jo Fitzgerald
Jo Fitzgerald
31st Jan 2014

Having written articles on how to create a Drupal 8 field type, field widget and field formatter I thought that now is the time to explain why you might want to create a custom field type. More specifically, why I have created a custom field.

To provide some context: my pet Drupal 8 project is to produce a companion site for players of the Fantasy Football (soccer) game Fantasy Premier League (N.B. this is not my site :) ). For the uninitiated, Fantasy Football, as described by Wikipedia, is "a game in which participants assemble an imaginary team of real...

Read more