We started to migrate our sites from drupal 7 to drupal 8, but we need our modules also to be ported from drupal 7 to 8 and it’s time to porting the same, Due to the substantial changes in Drupal 8 from its previous versions, we developers find it hard to porting the modules from drupal 7 to drupal 8. This is mainly because Drupal 8 is object oriented and much closer to an Model View Architecture(MVC), Drupal is no longer a Presentation Abstraction Control (PAC) architecture framework, Drupal follows the PSR-4 folder structure in compatible with symfony component which Drupal 8 uses. to make our porting fast, we can use Drupal Module Upgrader
Lets see what is Drupal Module Upgrader?
Drupal Module Upgrader
Drupal Module Upgrader is a module which scans the source of a Drupal 7 module, and that flags any code that requires updating to Drupal 8 and it will attempt to *convert* the drupal 7 code automatically to the Drupal 8 version using the relevant API changes which notices from List changes
For a full description of the module, visit the project page:
Installing the module
This module requires drush 8 or above, Assuming the that drush 8 installed in your system, if it isn’t please visit how to install drush with composer.
drush dl drupalmoduleupgrader
drush en drupalmoduleupgrader
- Place the Drupal 7 module which you wish to port into your Drupal 8 site's /modules directory.(not in sites/all/modules as like in drupal7)
- To scan code and get a report of code that needs updating and how, run the following inside the Drupal 8 root directory:
drush dmu-analyze MODULE_NAME
3. To attempt to upgrade your Drupal 7 module's code to Drupal 8 automatically, run the following inside the Drupal 8 root directory:
drush dmu-upgrade MODULE_NAME
4. The script will output a few lines as it attempts various conversions. Go into your modules/MODULE_NAME directory check out all of your new YAML files and such;)
Workarounds to @FIXME Tags
- Enabling your module can still throw off errors and/or give you a white screen death, even after the dmu-upgrade has executed successfully, This is mainly because the program while executing, skips call by references and minute changes like that. If you read your code after dmu-upgrade is done, you will see comment tags @FIXME. This is to indicate where the changes have to manually be done. Almost every change will be mentioned throughout the code and links to the corresponding change records are present in the html file generated by dmu-analyze
- Only run dmu-clean after the code is bug free and perfectly functional. Otherwise old code will be removed which had to be changed manually.
The Drupal Module Upgrader (DMU) module despite being in the development stages, saves developers a lot of time when upgrading modules to be compatible with Drupal8.