Picture
Arlina Espinoza Senior Technical Lead
March 13, 2020

Drupal 9 release date has been pinned for June 3, 2020, and it's coming up super fast. What does that mean for your site?

First of all, don't panic. Drupal 7 and 8 end of life are scheduled until November 2021, so there is plenty of time to upgrade. However it is always good to plan ahead with time and take advantage of the new features and security releases with the new version.

If you are on D7

Moving to Drupal 9 will be very similar as moving to Drupal 8, and in fact, there is no reason to wait, and the recommendation is to move to D8 as soon as possible, incorporating the tools described in the next section to search for possible incompatibilities.

Coming from D7, the greatest challenge might be the availability (or not) of the modules you already have installed, and finding and implementing replacements wherever needed. Take this as a chance to audit your site and plan a migration with a new architecture that fits your needs.

Also try out the Upgrade Status module, as it "checks the list of projects you have installed and shows their availability for newer versions of Drupal core".

If you are on Drupal 8

At its core, Drupal 9 will be the same as the latest release of Drupal 8, minus the deprecated components removed, and third party dependencies updated. This means that an upgrade from D8 should be fairly easy as it only involves making sure your codebase isn't making use of deprecated code.
Checking your site for readiness is simple using the mglaman/drupal-check utility. It is a simple CLI tool to generate a report of deprecation errors. Install it as a development package on your site and use:


# Install:
composer require mglaman/drupal-check --dev

# Run on a directory:
drupal-check web/modules
Drupal Check CLI tool example

Some things to keep in mind while checking deprecation notices:

  • Update all modules to the latest development version, to ensure testing against the latest code.
  • Don't just check the contrib modules, run it against themes, profiles and custom code.
  • If your project has continuous integration, aim to incorporate this tool into the workflow to verify readiness and avoid regressions.
  • Don't run this tool in a production environment :)

If CLI tools aren't your fancy or would like a nicer UI to show to project managers and clients, the Upgrade Status module will provide a nice dashboard with a summary and detailed information for each module of your site. It uses drupal-check as it's underlying tool.

Upgrade Status module report

 

Fixing deprecations

Now that you've got a report of deprecated code usage, it's time to fix it. The deprecation notices should state clearly what is deprecated, and suggested changes. I also like to look at the source code of the deprecated function and see what Drupal core is using inside it, as it shows unequivocally what needs to be done.

Let's take an example:


Call to deprecated constant REQUEST_TIME: Deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal::time()->getRequestTime();

Fixing the error can be as simple as replacing REQUEST_TIME with:


\Drupal::time()->getRequestTime()

In fact, a tool called drupal-rector is under development to help automate this process. A handy list of deprecation fixes can be found in the drupal/check documentation as well.

However be aware that \Drupal calls should be avoided in classes whenever possible, and dependency injection used instead. So for the example above, if REQUEST_TIME was used inside a service class, we'd inject the 'datetime.time' service into it (the service returned by \Drupal::time()) and then call getRequestTime() on it. For more in-depth information on how to call services using dependency injection, read Accessing services from the drupal.org docs.

Mark your modules as D9 ready

If you have fixed all deprecation notices, and are a module maintainer or have custom modules in your site, mark them as compatible with Drupal 8 and 9 in the info.yml file:


name: My Module
type: module
core_version_requirement: ^8.8 || ^9

 

A note on third party dependencies

Drupal 9 will have it's third party dependencies updated, most notably Symfony 4.4 components. Be sure to test your site in a D9 beta using these dependencies to avoid potential conflicts when D9 is released. Make sure you are running with the recommended dependencies versions by using the 9.0.x branch of drupal/core-recommended.

Finally, if you are starting a new build

Start with the latest D8 release! As mentioned, Drupal 9 is D8 at its core, so it is safe to start development with Drupal 8 and wait for the release date to upgrade. Just keep an eye out on module deprecation notices using the suggested tools from above.