Skip to main content

Planet Drupal

Content that's out of this world ...

Planet image
The articles on this page are ComputerMinds' contribution to the Planet Drupal aggregated article feed.  Planet Drupal is intended to collate interesting and useful Drupal content from around the web.

Removing invalid query string parameters passed to a view

3rd May 2023

As a Drupal site administrator, you may notice in the website logs that there might be a large number of repeated log messages along the lines of "An illegal choice has been detected. Please contact the site administrator." We recently had this problem on a Drupal site that was upgraded from Drupal 7 to Drupal 9 which featured a product search that was built using Views.

Due to slight differences in the way in which the view and facets were built in the Drupal 9 site, this resulted in slightly different URLs being used when the user would filter the...

Read more

How to: Implement an automated Commerce Order state transition

3rd Apr 2023

A common requirement for any website that sells products is to have a mechanism in place that ensures orders placed on the website are 'Exportable' - being made available as a file that can be sent across to a different system, to handle the processing of the order.

The Drupal Commerce 2.x module (for Drupal 9, 10) has the concept of order 'Workflows', along with defined 'States' and 'Transitions'. A workflow is a set of states and transitions that the order will go through during its lifecycle. Transitions are applied to an order and this will progress the order from...

Read more

Migrating cropped images

13th Mar 2023

One of our big Drupal 7 to Drupal 9 migration projects included bringing across image cropping functionality and data on a longstanding client's website. This site had used the Imagefield Crop module, but that was only for Drupal 7. We set up Image Widget Crop for the new site, which is better in a few ways but is also fundamentally different. The old site referenced the cropped images from content, only bringing in the originally-uploaded images for edit pages, to allow editors to adjust the cropping, which was then used wherever that image appeared on the frontend. But the new Image Widget Crop module allows configuring different crops for different situations.

The real challenge was in migrating the data! But we call ourselves Drupal experts, so of course we dug to find solutions. We found the following steps were necessary...

Read more

Drupal 10 upgrade: Custom code upgrades

7th Mar 2023

This one is entirely on us, we wrote the custom code, which makes us responsible for maintaining it.

The upgrade status module gives us a nice report of each custom project and what changes it thinks are required to bring the code up to date to work with Drupal 10.

We really don't have a lot of custom module code, and the code that we do have is very simple, standard Drupal 8/9/10 stuff, so there are a couple of calls to taxonomy_term_load_multiple_by_name to remove, and an accessCheck to add to an entity query, but other than that our custom...

Read more

Drupal 10 upgrade: File to media

2nd Mar 2023

We're continuing our series on upgrading this very website to Drupal 10...but our first proper bit of work to upgrade this site is essentially nothing to do with Drupal 10!

We built this site in the early days of Drupal 8 and Drupal core didn't really handle 'media' any differently to Drupal 7, but we wanted to try out some new modules that included having a library and drag&drop upload. However, these modules are an additional thing that we need to upgrade and have been pain in that sometimes the buttons don't appear, or they're buggy in other ways. Anyway...

Read more

Drupal 10 upgrade: Defining the project scope

25th Feb 2023

Let's define the scope and goals of our project to upgrade this very website to Drupal 10.

Essentially, that's it: we want to upgrade this website to Drupal 10 so that we can benefit from security releases etc.
At the moment we want to do so with the minimum of effort, so I don't want to have to be writing lots and lots of code or changing fundamentally how the site works, but I am up for simplifying things if it gets us to a point where we have to maintain less code.

Since Drupal 9, major version upgrades now...

Read more

Drupal 10 upgrade: Introduction

22nd Feb 2023

On 14th December 2022 Drupal 10 was released. We can't say we immediately set about the task of upgrading all our Drupal 9 sites, but we did start thinking and planning to move all our sites in 2023.

I thought it might be fun to take a look at how we do an upgrade and specifically the upgrade of this very website.

So over the next few weeks we'll be slowly getting this site ready and as up to date as possible before making the jump up to Drupal 10.

We've got a few challenges ahead, this site was originally...

Read more

Allow editors to use HTML attributes by default

26th Oct 2022

Drupal provides an excellent sanitisation system to filter the HTML content that editors might create. Think of it like a series of traffic cops that filter different vehicles into different lanes. Some content is allowed through to its destination, some has to be transformed along the way, and some is simply blocked from displaying. Administrators can use the 'Limit allowed HTML tags and correct faulty HTML' option to configure which HTML elements and attributes they can use. This helps protect a site against nefarious HTML - whether it might be malicious or just ugly. Under Drupal 9, editors can't use...

Read more

PhpStorm coding tip for Drupal services

29th Jun 2022

Here's a super simple tip to help you work with services for Drupal in PhpStorm (our favourite IDE). First, ensure you have enabled the Drupal Symfony Bridge and Symfony Support plugins; they're brilliant for auto-complete suggestions, and navigating around services, controllers, annotations and twig templates! I find it so helpful to be able to cmd+click (or ctrl+click) on a service name, whether in a YAML definition, or PHP code, and jump straight to the service class. But I'd noticed that PhpStorm often didn't recognise the method used after my code referred to a service like this:

\Drupal::service('my_service')
  ->something($id);
Read more

Get Hook-ed on Object-Oriented Programming

15th Sep 2021

Does writing hooks make you sad because the code is too procedural? Are you keen to use the object-oriented programming approach that Drupal and its service container enable, wherever you possibly can? Read on if you answered yes to any of those questions.

Read more