Drupal 9

Posts about Drupal 9, the open source content management system.

Drupal Logo

Drupal 9: Creating Custom Twig Functions And Filters

1st November 2020 - 6 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.

Setting Up

Before we can create Twig filters and functions in Drupal we need to tell Drupal that we have a class that contains them. This is done by creating an entry in the your module services file that contains the tag tag.extension. In a module called "custom_twig" the file would be called custom_twig.services.yml and would contain the following.

Drupal Logo

Drupal 9: Getting Setup Quickly With DrupalVM

11th October 2020 - 7 minutes read time

I like working with DrupalVM and I've worked with Ansible based Vagrant setups for years and so I'm very familiar with it's setup. More than that, I find I have very few problems with running it. I normally run it with Vagrant, but you can run it with Docker if you like.

When starting a new site project I normally add DrupalVM to the codebase so that I can get the site up and running quickly. This is especially useful if something like Solr is involved as setting that up is a pain. I thought I would go through the steps involved in adding DrupalVM to your codebase as it's pretty simple and will get you up and running with a Drupal site in about 10 minutes.

Start out with a Drupal site in a composer setup. I normally run the Drupal recommended composer setup file so that I have a up to date Drupal codebase, so let's do that here.

Drupal Logo

Drupal 9: 7 Composer Tips

1st October 2020 - 14 minutes read time

I've been using composer with Drupal for a few years now and I've picked up a few things along the way that have really helped me out. Following on from my post about the anatomy of the recommended Drupal 9 composer file I thought it would be good to expand on that to present some tips.

Here are 7 tips that will help you out when using composer with Drupal.

Automatic Patches With Composer

One of the most useful things I have found is using composer to manage patches to projects. This is possible using a project called composer-patches. You can require this into your project like this.

Drupal Logo

Drupal 9: Anatomy Of The Drupal Recommended Composer File

20th September 2020 - 12 minutes read time

According to the official Drupal documentation, to create a new site using composer you should use a composer template project called drupal/recommended-project. This has a default composer.json file setup with some values that will help you get up and running swiftly with a new Drupal project.

It's a good initiative to get you up and running with a standard Drupal site pretty quickly. I've used this composer project a number of times now, but I haven't really looked at what's in it. I thought I would dive in and see exactly that's in there and dissect it line by line.

To reiterate what's in the Drupal documentation, to create a brand new Drupal project using composer use the following command.