Oneliners, Tips and Tricks to facilitate upgrading to Drupal 10

By Bill Seremetis, 21 October, 2023

Drupal 9 is now EOL. It turns out, there are a lot of sites that haven't made the upgrade to Drupal 10 yet though! Upgrading to Drupal 10 is neither easy nor hard, but it is something you should not ignore. Below are some handy tricks to help you in this quest, also do not hesitate to contact me if you need help upgrading and maintaining your Drupal site.

My current role at managed services has me upgrading sites by the dozen. Together with my magnificent team we maintain about 100 Drupal websites, some of them high-profile, some of them small and casual. Upgrading all of them taught us valuable lessons and while at it I've created some handy one-liners to help ease the process. Let's go then!

Use Upgrade Status

This goes without saying, use and follow the suggestions it makes.

Invest into Visual Regression Tests

This is a nice to have, but absolutely needed if you are using twig_extensions, unified_twig_ext, twig_tweak and other similar modules. I advise you to setup some visual regression tests using BackstopJS to highlight differences before and after you upgrade code. An ommitted CSS class can be hard to spot without using such a tool.

Pro Tip: If you use DDEV have a look at

Handy scripts and oneliners

Fix spaceless deprecations everywhere

Please run these under the custom theme. Check git diff before committing.

find ./ -type f -name '*.twig' -exec sed -i 's/% spaceless %/% apply spaceless %/g' {} \;
find ./ -type f -name '*.twig' -exec sed -i 's/% endspaceless %/% endapply %/g' {} \;

Find all queries that might need applying accessCheck

See Change Record: Access checking must be explicitly specified on content entity queries

Find files and open in Vim:

find ./ -type f -exec grep -q '->execute' {} \; -exec vim {} +

Note: use :n to go to next file.

Other options:

  • phpStorm: Ctrl+Shift+F in custom modules folder, search for ->execute
  • bash with silversearcher-ag: ag '\->execute'
  • bash with ripgrep: rg '\->execute'

Find for-ifs in twig files

Find all twig lines that use an if condition on a for:

rg -t twig 'for.*if'

Requires ripgrep. Other tools can do it but they'll be very slow.

See for how to fix it.

How to fix drupal_get_path

-    $this->modulePath = drupal_get_path('module', 'mymodule');
+    $this->modulePath = \Drupal::service('extension.list.module')->getPath('mymodule');

Simple as above, use \Drupal::service('extension.list.module')->getPath('module_or_theme_name') and use module or theme as needed.

The "node_type" plugin does not exist.

find . -type f -name 'pathauto.pattern.content_*.yml' -exec sed -i 's/node_type/entity_bundle:node/g' {} \;

When you try to edit a node, you might get an error saying The "node_type" plugin does not exist.. If so, the issue is probably with an update to ctools/pathauto. To get around it, in each of you pathauto.pattern.*.yml files, open the file, find the string node_type and change it to entity_bundle:node. Then import the config to your site again. You should now be able to edit your pages.

Modules known to be affected by this issue:

  • pathauto: pathauto.pattern.*.yml
  • block_visibility_groups: block_visibility_groups.block_visibility_group.*.yml