fbpx Drupal 8 | ComputerMinds 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

How to write a PHPUnit functional test for Drupal 8

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
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
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 what it...

Read more

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

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:
/lib/Drupal//Plugin/field/widget/.php
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 * Contains \Drupal\<module_name>\Plugin\field\widget\<field_widget_name>....
Read more

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

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...

Read more

Drupal 8: Creating a custom field - Part 1: Field type

Jo Fitzgerald
28th Jan 2014

I have been experimenting with the Alpha release of Drupal 8 and so I'm sharing some of my experiences so that you can avoid the pitfalls I have encountered.

First I would like to give credit to the two articles I used during the exercise:

Hopefully this article will provide a third point-of-view to make your task easier.

a) Create the file

In D8 the location of files is very important. The field type must be located as follows:
/lib/Drupal//Plugin/field/field_type/.php
N.B....

Read more