Deprecated Code

Let's just say, your code becomes deprecated when it is no longer the best way to achieve the original goal. They deprecate code instead of outright deleting it to provide backwards compatibility and to make sure they don't release the code that breaks the sites.

Symfony and Twig Versions are Updated

"Drupal 9 will ship with either Symfony 4 or 5, and with version 2.0 of Twig. These are both major upgrades for core Drupal components, so it's great news for Drupal to benefit from the security, performance, and developer experience improvements in both. Along these lines we should also expect the PHP requirements to increase in Drupal 7 to PHP 7.2, 7.3, or possibly 7.4. "

Is it Necessary to Upgrade to Drupal 9?

It is necessary and highly recommended that you upgrade to Drupal 9 before November 2021 because after this date, those versions 7 or 8 will no longer be supported by the Drupal Security Team which means no future security patches or bug fixes will be released for these versions ..

What is the impact of Drupal 9 Release to Developers?

What does this mean for module developers and site maintainers? Fortunately, if your site works for Drupal 8.9.x it will work for 9.x as the only change between the releases is the removal of deprecated code. After updating to 8.9.x, You'll want to update each contrib module currently installed on your site. Even so, the best way to be 100% confident that your site is Drupal 9 ready is to use the drupal checker command line tool to scan your custom and contrib code.

How to Install and Run Drupal-check in you Command Line?

  • Run  composer global require mglaman / drupal-check
  • Run  composer drupal-check path

Note: Change the PATH to the directory you want to check.

If you encountered error about phpUnit, just run  composer require phpunit / phpunit: ^ 8.0 --with-all-dependencies.

Changing Module to be Ready for Drupal 9

Make sure that your current Drupal version is 8.8.x or latest for it to go smoothly. But if your current Drupal version is 7.x or something, update it first to Drupal 8.8.x.

These are the Steps to Update the Contrib Module:

  1. Install Drupal Check
  2. Run drupal-check
  3. Update the info.yml file (if there is core: 8.x or something , remove it)
  4. Change it to  core_version_requirement:'^ 8 || ^ 9'
  5. Fix all the Deprecated code reported

When running drupal-check, it will print the file, line number, deprecation number and the total number of errors. Just like in this image:

Drupal-check

How to Fix Deprecated Code?

There are two ways on how to fix deprecated code:

  • Manual Process

          locate the file of the deprecated code and change it for the compatibility of Drupal 9

  • Writing a Patch to fix Deprecated Code.

          While patching the issue it is important that we follow best practices and use dependency injection rather than calling the drupal service container.

After fixing all deprecated code, your on your way in updating your site to Drupal 9.