Browse cities

How should you prepare for Drupal 9? You deep clean up your codebase of all deprecations and errors and wait patiently for the big upgrade to... happen.

“As long as your Drupal 8 website is not using deprecated code, the upgrade will go smoothly.” (source: Third and Grove)

“But how do I know whether my Drupal website's using any code deprecations?” you'll legitimately ask yourself.

How do you identify and make an inventory of all the code errors on your site, so you can remove them and start... waiting, patiently, for that big upgrade to Drupal 9?

Well, you “stuff” your toolbox with all the essential tools that'll help you track down deprecations (still) lurking in your codebase.

Here are the 5 most effective ones:
 

1. Drupal Check 

You can't claim that you're getting ready for Drupal 9... the proper way if you're not already using Drupal Check to scan your codebase for deprecations.

“But what is Drupal check?”

It's a command-line tool — a custom runner for PHPStan — that enables you to run PHPStan against your Drupal website to look for any deprecations and code errors.

In short: instead of running PHPStan, you run Drupal Check, which comes as a package storing PHPStan, PHPStan Drupal, PHPStan's Deprecation Rules, plus configurations for them all, as well.

How to Prepare for Drupal 9: Drupal Check

Source: glamanate.com

Just incorporate it into your build processes and continuous integration systems and run audits on:
 

  • your custom and contributed modules, checking their compatibility with Drupal 9
  • your D7 to D8 migration code
     

Use it on your existing Drupal 8 website. Or use it on the one that you're developing, when you're nearly done, to check whether any deprecations have made their way to your codebase...

Word of caution: expect Drupal Check to provide you with an accurate report of the deprecated code used on your site, but don't expect it to fix them for you, as well.
 

2. Upgrade Status Module  

Here's another “tool” that you shouldn't miss from your toolbox. That if you do want your website's upgrade to Drupal 9 to be... buttery smooth.

How to Prepare for Drupal 9: The Upgrade Status Module

Source: Drupal.org

What the Upgrade Status module does is:
 

  • inspect your code — your custom and contributed projects — for deprecations
  • make an inventory of all the identified issues 
     

Moreover, its Drupal 8 version harnesses the power of PHPStan and comes as a complete solution that you can use for running full-site checks.

Let it work its “magic” on your Drupal site and find out where it stands in terms of compatibility with Drupal 9.
 

3. PHPStan & PHPStan-Drupal        

PHPStan's the very foundation of the toolkit to rely on when you prepare for Drupal 9. 

How to Prepare for Drupal 9: PHPStan and PHPStan-Drupal

Source: Matt Glaman's Twitter page

Not only that you save valuable time using it, time that you'd otherwise invest in pinpointing every error spotted during your code reviews:
 

  • classes called incorrectly
  • nonexistent classes
  • PHP projects that you forgot to run once you compiled them
     

…  but you get to write your own custom rules.

You get to indicate specific “red alarm” situations that you'd want PHPStan to... investigate for you.

Now, it may be the key tool to keep at hand when you evaluate your site's compatibility with Drupal 9, but nevertheless... it does have its own limitations:

It won't load any files on its own if you run it against a Drupal module out of the box. It depends on Composer to load all that information...

Luckily, Matt Glaman's developed an extension to address precisely this... limitation of PHPStan: phpstan-drupal. 

An extension that'll help you make the most of PHPStan when using it to scan Drupal code: from your various dependencies to... Drupal core. 
 

4. Use Project Deprecation Status to Prepare for Drupal 9 

And what this tool does is answer one key question:

“What's the current status of the Drupal modules in terms of compatibility with Drupal 9?”

Which Drupal projects are already compatible and which of them need more fixing before the big upgrade?

Project deprecation status is the right tool to... gain an accurate picture of where each Drupal project stands in relation to upcoming Drupal 9.
 

5. Rector       

So far I've pointed out the 4 key tools for deep-scanning your Drupal website to detect any uses of deprecated code as you prepare for Drupal 9.

But what if you want to get rid of that pile of deprecations that you will have collected by the end of the scanning process?

How do you fix/remove them?

How to Prepare for Drupal 9: Rector

Source: Pronovix.com

And, more importantly: how do you automate this code cleaning process?

In this respect, Rector for Drupal 8 — a proof of concept for now — comes with great potential:

Check it out and... be prepared to add it to your toolbox for any automated deprecation fixes that you'll want to perform on your site.
 

The END!

These are the 5 essential tools to have in your toolbelt for running deprecation checks on your Drupal website, getting all ready for Drupal 9.

Would you have added some other must-have tools to the list, as well? Let us know in the comments here below:

Image by Michael Schwarzenberger from Pixabay

Development

We do Drupal development

Go to our Drupal page!

Visit page!

Recommended Stories

How Creating a Mind Map Helps You Make Your Website More User-Friendly
The line between useful and... useless (or pushy or simply annoying) is thinner than you think. That's why… (Read more)
Adriana Cacoveanu / Dec 14 '2019
Why Would You Build Your Own Cloud Native Drupal Platform? The Main Benefits and Challenges to Consider
Why or rather "when" should you consider building your own cloud native Drupal platform?  Is a container-based… (Read more)
Silviu Serdaru / Dec 12 '2019
The Web Experience Toolkit Drupal 8 Distribution: Why Use a Drupal Distribution and Why Precisely... Drupal WxT?
Say you need to build a company website that's bilingual from the ground up, accessible, responsive, user-friendly… (Read more)
Adriana Cacoveanu / Dec 10 '2019