![]() And in many cases working is good enough. One thing I noticed when running drupal-rector is that in some cases while the suggested fix would technically work, it's maybe not the technically correct approach. Prefer a UI solution instead of the CLI? Gábor has a great video showing how to use the Upgrade Rector module to produce a diff via Drupal's UI. If you're happy with what you see, go ahead and remove the -dry-run flag and let 'er rip. * DrupalRector\Rector\Deprecation\DBSelectRector $consumer_data = \Drupal::database()->select('consumer_field_data', 'cfd') $consumer_data = db_select('consumer_field_data', 'cfd') we can't use the entityTypeManager here, or we'll have -71,7 71,7 If they exist, load any overrides defined by that consumer. ![]() 2) web/modules/custom/lehub/src/LehubConfigOverrider.php dry-runĪnd it'll output examples of all the changes that would be made if you ran it without the -dry-run command. These paths should be relative to the rector.yml file. You'll want to adjust the path to the drupal-8-all-deprecations.yml, and Drupal code directories like web/core to make sure they match your project's layout. My codebase looks like this: ├── README.md ![]() I created this in the root directory of my Drupal project, alongside the vendor/ and web/ directories. Install drupal-rector using Composer composer require -dev palantirnet/drupal-rectorĬreate a rector.yml configuration file. Switching to a newer version solved the problem. I initially tried using PHP 7.1 and got some cryptic errors related to PHP autoloading. Running drupal-rector requires a minimum of PHP version 7.2. I recommend you do this in a Git branch so you can easily view a diff of the changes, and revert anything that doesn't work.Īnd. Note: Using drupal-rector can cause changes to your codebase. But it does cover the most common examples of deprecated code use and in many cases that might be all you need.Įither way, it's a great way to get a jump-start on ensuring your custom Drupal modules are Drupal 9 ready. It's a wrapper around the Rector project that provides rules covering the most commonly-used deprecated code in Drupal. A more complex example would be automating the update from PHP 5.3 to PHP 7.3.ĭrupal Rector can also automate the removal of deprecated code and perform other refactoring required to make a Drupal 8 module ready for use with Drupal 9. A simple example would be renaming a class, and finding all the places in the codebase where the class is used and updating those as well. Rector is a PHP project that given another PHP codebase can apply a set of rules that refactor the PHP and output an updated codebase. What do you want to cover over the next few months that'll help you prepare for Drupal 9? /UQK9pa2Dvh- Joe Shindelar March 12, 2020Īnd one of the things I learned about was the Drupal Rector project from Offer Shaal and others. /bin/drupal-check -ad modules/custom/lehub/Ībout a month ago I posted on Twitter asking what people were interested in learning about in preparation for Drupal 9. # Another common location is vendor/bin/drupal-check. Here's an example of running drupal-check against a specific module ( lehub is our custom module): # The path to the executable may differ depending on your Composer configuration. Use this command to verify the install worked and view available options. Note: Drupal Check needs to be run from the root directory of a Drupal project in order to work. Install drupal-check in an existing project as a development dependency using Composer: composer require mglaman/drupal-check -dev \Drupal\Core\Link::fromTextAndUrl() instead. ![]() In drupal:8.0.0 and is removed from drupal:9.0.0. Example deprecated code output -Ĥ03 Call to deprecated method l() of class Drupal: This makes it easier to locate the parts of your codebase that will need to be updated in order ensure Drupal 9 compatibility. and, Offer Shaal's Drupal Rector (drupal-rector)ĭrupal Check can scan for use of code and suggest a fix, as well as optionally perform static analysis.Matt Glaman's Drupal Check (drupal-check).To start figuring out what we need to change, and what it's going to take, I've been playing around with two helpful tools that I've been hearing a lot about lately: Slide from State of Drupal 9 by Gábor Hojtsy.
0 Comments
Leave a Reply. |