How to prepare your module for Drupal 9

Drupal 9 roadmap

Drupal 9 will be released in 2020.

If you are a contributor of any module on drupal.org and want those sites to live long after the end of life in 2021, you need to prepare for Drupal 9.

Why should you do it at all? First of all, users of your module may want to have it on Drupal 9. Secondly, your clients may ask to migrate their websites to Drupal 9, so it’s better to be ready.

Source: drupal.org

Also, after the Drupal 8 end of life, there won’t be any commits or new features.

Unsupported (not compatible with the latest Drupal core) modules and sites running by Drupal 8 will have vulnerabilities after some time

It is the most important to stay secure if you want to store your users’ private data safely.
And it is important if you need to scale your website and add new functionality.

Updating a codebase from Drupal 8 to 9  is not as hard as updating from 7 to 8.

Source: drupal.org

Only 5 easy but required steps and the last one is optional.

Step 1

The most important and easiest step is to remove the deprecated code. Some utilities can help you with it.

After installing it you’ll get a report about deprecated functions, classes, and so on.

Upgrade status

After that, you can see the problem code and fix it. The most of it is one line changes like drupal_set_message() to MessengerInterface::addMessage.

The most complicated part of this task is to change hook updates in the .install file. For example, you need to change an old class and method SqlContentEntityStorageSchemaConverter::convertToRevisionable to the new one EntityDefinitionUpdateManager::updateFieldableEntityType. You can see a full example here.

Step 2

But these tools are not perfect. They don’t show deprecated classes or services if you don’t use typehints. Most developers are lazy and don’t do it. For example, in custom constructors.

But also it must be changed in services files.

Step 3

You need to add the config_export section to your entities.

Step 4

Also, you need to fix your Functional test. There must be set the default theme property.

Step 5

You need to add the core_version_requirement key to the info yaml file.

Step 6 (additional one)

And the last one: if you want to save compatibility of your module with Drupal 8.7, you can use the next construction in some situations:

You need to check it. You may need to use this construction because of entityTypeManager property that was added only in Drupal 8.8 in the EntityViewsData class and many other classes.

Otherwise, you can set a version constraint and only allow usage for those who run Drupal 8.8+.

Besides, platform requirements have changed. Most importantly, this includes new minimum versions of:

  • PHP 7.3 or later
  • MySQL 5.7 or later

Now you prepared your module to the Drupal 9 release.

If you have any other issues you can send us an email - find the contact form below. See you!

You might also like

Five use cases that highlight the benefits of the Bibliography & Citation project

Before 2015 those professionals used the Biblio module to compile bibliographic data and design citations properly on their Drupal-powered websites. But the Drupal 8 era has begun but Biblio has not been ported to the new CMS version for some reason. And here we came into play with the Bibliography & Citation project that became the only alternative to Biblio. In this article, we gathered stories about the practical benefits of Bibliography & Citation, told by its users.

Why accessibility is important?

Imagine a person with a disability tries to order stuff from your delivery website and can’t because your website is not accessible. You lose money, miss new clients, and risk your neck actually: if a website or an app is not accessible, an owner can be sued. There is a set of standards though. Read more and stay safe.