How to prepare your module for Drupal 9

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.

Drupal 9 roadmap

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.

Drupal 9.0

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.

Migrate to Drupal 9
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