Your Drupal 8 to Drupal 9 upgrade will be "insanely" smooth.
With Drupal 9 built in Drupal 8, all there's left for you to do is to remove all deprecated API from your website.
Easier said than done...
Just imagine yourself fine-tooth combing your codebase to:
- identify all errors and fix them, one by one
- identify all deprecated code and remove it, manually, one by one
- apply the same code updates, repetitively, as many times as needed
But what if you could automate deprecated API use removal from your Drupal site?
You can, actually, with Rector-Drupal.
Let's dive into more details on this automation tool for Drupal 8:
1. How You'd Remove Deprecated Code Before Rector
Before we dig into Rector for Drupal 8 — what it is and how it makes your life easier — let's see what's the current way of identifying and removing deprecated code in your Drupal projects:
- first, you upgrade your contrib modules and theme to their latest versions
- next, you run drupal upgrade_status or drupal-check, which will generate a list of all the deprecations on your Drupal site
- for every module on the list, you go to Drupal.org to check whether it will be kept as such, upgraded, or ranked as “deprecated” starting with Drupal 9
- you run the all the patches that you will have found available: basically, you manually fix all the errors detected in your codebase
- you run drupal upgrade_status or drupal-check again to see whether there's any deprecated code still lingering on your Drupal site
Note: if there are multiple instances of one deprecation, you'll need to address it for each and every occurrence.
In short: updating code to get your website Drupal 9-ready — fixing all the errors, removing all the deprecations — means a lot of manual and repetitive work.
You now have Drupal-Rector to automate the whole process.
2. From Rector to Drupal 8 Rector, to Drupal-Rector
Drupal-Rector, the Palantir's tool for automating code updates and streamline the Drupal 8 to Drupal 9 process, didn't come out of anywhere, you know.
2.1. What Is Rector?
"A reconstructor tool- it does instant upgrades and instant refactoring of your code." (Github.com)
It's designed (by Tomas Votruba) to automatically:
- run PHP code and framework updates
- improve your code with code quality and code style fixes
2.2. And What Is Drupal 8 Rector?
“... the missing bridge to enable automated code upgrades from Drupal 8 to 9” (Palanatir.net)
2.3. What Is Drupal-Rector?
The Palantir team took over from there and introduced their own version of the Rector for Drupal tool.
Each rule will upgrade the code corresponding to a specific deprecated API in use on your Drupal website.
The 2 obvious benefits of using it on your Drupal projects, as you get them ready for the Drupal 8 to Drupal 9 upgrade, are:
- you streamline the whole process
- you reduce the upgrade costs (just think of all the time that you'd otherwise invest in addressing every single deprecation issue, one by one; even if the same issue appears in different areas of your codebase)
3. How Do You Use Drupal-Rector?
They have a step-by-step guide on Github on how to set up your code updating process using this automation tool:
- you give your code a deep-scan using Rector and analyze the code fixes that it suggests you to make
- you go ahead and... apply those fixes
As simple as that.
4. Why Incorporate Drupal-Rector into Your Drupal 8 to Drupal 9 Upgrade
Now, let's talk... benefits.
- to fix code quality issues
- to upgrade your PHP version
- to upgrade from Simfony 3 to Symfony 4
- to Rename classes, properties, methods, namespaces or constants
- to remove deprecated API
In short, by using Drupal-Rector you get to automate (or at least semi-automate) code upgrade to Drupal 9.
5. Drupal-Rector: What's Next?
In other words: what should you expect from this tool in the nearest future?
The Palantir team's plan is to create 15 rules standing for the most common deprecations in Drupal 8.
What do you think of this automation tool aimed at jump-starting your Drupal 8 to Drupal 9 upgrade?
Have you used it? Would you use it?
Are there any specific code error or deprecation issues you wish it addressed?
Photo by Danial RiCaRoS on Unsplash