Drupal 8

Drupal 8: Creating A Subquery In Views

7th November 2020 - 5 minutes read time

You've probably been there before. A Drupal View you are working on looks great and has all the data and fields you need, but when you look a little closer at the results you realise that something is off. After looking at the generated SQL query you see that there is a problem with one of the joins which causes your counts to be off a little. Ultimately, you need to remove this join, but you really need that data included in your results.

Creating a subquery can allow you to pull out data from a specific field without adding another join that would cause the results to be out.

Drupal 9: Creating Custom Twig Functions And Filters

1st November 2020 - 4 minutes read time

Whilst Twig is a powerful tool in its own right there are occasions when you need to pull out data from Drupal or manipulate it in certain ways. I normally do this using preprocess steps, but I recently found that it was also possible to extend Twig within the Drupal framework to provide your own functions and filters. This can be useful if you have custom templates and need to perform special actions on data items to format them in different ways.

Drupal 8: Adding Events To Existing Behaviours

15th September 2020 - 6 minutes read time

I recently needed to add functionality to the Password Policy module so I thought I would outline the steps I took in a blog post. The Password Policy module is used to enforce a stricter password policy on users on a Drupal site. This means that when a user creates or changes their password they must conform to certain rules like the password length, or if it contains upper and lower case characters. There are a set of rules to chose from and they can be fully customised by the site administrators.

Drupal 8: Configuration Originates From A Different Site

25th August 2020 - 2 minutes read time

One gotcha when importing configuration to a Drupal site can be a message that tells you that the configuration you are trying to import is from another site.

Here is the error that can be seen on the Configuration Synchronize page.

Drupal 8: Install Site From Existing Configuration

19th August 2020 - 4 minutes read time

Installing a Drupal site from configuration is useful when running tests or if you don't have a copy of the database. You'll get a copy of the Drupal site without any content that will act in the same way as the live site. You can use modules like default content to add content into the mix so your newly installed site acts a little bit more like the live version.

Since there are some prerequisites to get this up and running I thought I would run through what is needed to get this working and how to run it.

Config Sync Directory Setting Change In Drupal 9

19th August 2020 - 1 minute read time

A change that was snuck into Drupal version 8.8.0 and wasn't mentioned in the 8.8.0 change notes was a small change to the setting that controls the placement of the configuration directories. The alteration deprecated the $config_directories setting from the settings.php file and move the configuration into the $settings array. You can see the detail behind this change on the Drupal change record.

Drupal 8: Automated Spam Protection

24th July 2020 - 7 minutes read time

Spam is a constant problem for any site on the internet that has a publicly available form, but automatically preventing spam can be tricky. The idea is to prevent the automated spam bot from being able to submit data to your site, but not at the detriment of the users. There is a careful balance between preventing spam and prevent real content being submitted by real users. Manually moderating blog comments is usually a good idea, but many websites contain contact forms and user registration forms that are often targeted by spam bots.

Getting Ready For The Upgrade To Drupal 9

21st May 2020 - 6 minutes read time
Drupal 9 will be released on June 3rd, 2020 so with this just around the corner I thought I'd put together a post about how to check if your site is ready. The transition from Drupal 7 to Drupal 8 was more of an upheaval than an upgrade. Updating a Drupal 7 site to Drupal 8 requires a lot of effort involving code changes and migration steps. Drupal 7 modules are not compatible with Drupal 8 and so any custom code written needs to be adapted to the new structure of Drupal. The difficulty of this change made the Drupal community take notice and think about how future versions of Drupal are introduced.

Drupal 8: Creating A Views Results Area Plugin

23rd March 2020 - 3 minutes read time

Drupal Views is a great way of exposing data to users via a search interface. This can be done directly via the database or via a Solr server. Plenty of Views plugins exist to allow reacting to the search input and output in a variety of different ways.

The other day I needed to add a personalised message to Views output to inform a user that their search keyword didn't find any results. There is a plugin for Views that allows this, but it only shows a basic search string.

Drupal 8: Theming With Tailwind CSS

8th March 2020 - 8 minutes read time

Upon a recommendation from someone in my local Drupal user group I decided to give Tailwind CSS a go. The ultimate aim of this was to replace the base theme I am using here with a more stripped down theme. At the time of writing this I am using the Cog theme, and whilst it has it's merits, I find that it's a little too much for this simple site.

I decided, therefore, to create a new theme and use Tailwind CSS to alter the site a little. This meant an exercise in integrating Tailwind CSS into a Drupal theme.