[SOLVED] How To Upgrade Contributed Module Of Drupal 7 To Drupal 8 Using Drupal Module Upgrader
BY akhila.vn
6 months ago
comments comment

For upgrading any of your contributed Drupal 7 modules, you just need to follow the few steps shown below. First of all you have to make sure that Drush is installed. If not installed, follow the steps from here.

Now install a fresh Drupal 8 in your system using Drush commands or directly download from Drupal.org. You must be aware that Drupal 8 has changed its structure from Drupal 7 in configuration, theming, folder structure etc. So now we can find the contributed and custom modules in the modules folder in the root directory. It is also better to create a contrib folder in modules folder for both DMU (Drupal Module Upgrader) and your Drupal 7 module for migration.

And now let's have a look at DMU. Drupal Module Upgrader is a script that scans and upgrades the source code of your Drupal 7 module, it also generates a list of new fixes with information links to Drupal.org as an upgrade-info.html file that will be available in your upgrading module directory. Also note that, this DMU scripts will run using Drush and Composer.

Now get into your Drupal 8's contrib folder using the terminal (For example: cd public_html/d8/modules/contrib) and follow the steps :

  • Download DMU using the drush command drush dl drupalmoduleupgrader. For example :
    xx@xx:~/public_html/d8/modules/contrib$ drush dl drupalmoduleupgrader
    Project drupalmoduleupgrader (8.x-1.2) downloaded to                 [success]
  • Now get into your Drupal module upgrader folder and install Composer. For example:
    xx@xx:~/public_html/d8/modules/contrib$ cd drupalmoduleupgrader/
    xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ composer install
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
      - Installing cebe/markdown (dev-master f89dc1d)
        Cloning f89dc1da1fc6823f0286d6cad736a642efd0f59e
      - Installing phpdocumentor/reflection-docblock (2.0.4)
        Loading from cache
      - Installing grom358/pharborist (dev-master 0db9e51)
        Cloning 0db9e51299a80e95b06857ed1809f59bbbab1af6
      - Installing symfony/filesystem (2.6.x-dev 823c035)
        Cloning 823c035b1a5c13a4924e324d016eb07e70f94735
      - Installing symfony/finder (2.6.x-dev 203a10f)
        Cloning 203a10f928ae30176deeba33512999233181dd28
      - Installing mikey179/vfsstream (v1.5.0)
        Loading from cache
      - Installing phpunit/php-token-stream (1.4.8)
        Loading from cache
      - Installing symfony/yaml (v2.7.4)
        Loading from cache
      - Installing sebastian/version (1.0.6)
        Loading from cache
      - Installing sebastian/global-state (1.0.0)
        Loading from cache
      - Installing sebastian/recursion-context (1.0.1)
        Loading from cache
      - Installing sebastian/exporter (1.2.1)
        Loading from cache
      - Installing sebastian/environment (1.3.2)
        Loading from cache
      - Installing sebastian/diff (1.3.0)
        Loading from cache
      - Installing sebastian/comparator (1.2.0)
        Loading from cache
      - Installing phpunit/php-text-template (1.2.1)
        Loading from cache
      - Installing doctrine/instantiator (1.0.5)
        Loading from cache
      - Installing phpunit/phpunit-mock-objects (2.3.7)
        Loading from cache
      - Installing phpunit/php-timer (1.0.7)
        Loading from cache
      - Installing phpunit/php-file-iterator (1.4.1)
        Loading from cache
      - Installing phpunit/php-code-coverage (2.2.3)
        Loading from cache
      - Installing phpspec/prophecy (v1.5.0)
        Loading from cache
      - Installing phpunit/phpunit (4.8.9)
        Loading from cache
    phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
    phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
    sebastian/global-state suggests installing ext-uopz (*)
    phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
    phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
    Generating autoload files
  • Get back to your contrib folder and clone your Drupal 7 module to it. You can find its cloning commands from its Drupal.org version control page. Here for example: commerce_techprocess is used as Drupal 7 module for migration.
    xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ cd ..
    xx@xx:~/public_html/d8/modules/contrib$ git clone --branch 7.x-1.x http://git.drupal.org/project/commerce_techprocess.git
    Cloning into 'commerce_techprocess'...
    remote: Counting objects: 23, done.
    remote: Compressing objects: 100% (22/22), done.
    remote: Total 23 (delta 6), reused 0 (delta 0)
    Unpacking objects: 100% (23/23), done.
    Checking connectivity... done.
  • Get back to your site root directory and enable drupalmoduleupgrader.
    xx@xx:~/public_html/d8$ drush en drupalmoduleupgrader
    The following extensions will be enabled: drupalmoduleupgrader
    Do you really want to continue? (y/n): y
    drupalmoduleupgrader was enabled successfully.                       [ok]
  • Now start analysing your module using the upgrader, it will list out the fixes and generate an html info file.
    xx@xx:~/public_html/d8$ drush dmu-analyze commerce_techprocess --path=modules/contrib/commerce_techprocess/
    Generated a report at                                                [success]
  • After all, you can upgrade your module using the command,
    xx@xx:~/public_html/d8$ drush dmu-upgrade commerce_techprocess --path=modules/contrib/commerce_techprocess/
    It will automatically create some of the Drupal 8 supporting files (for example: .info.yml, .routing.yml etc) and update some of your module codes, and other main functionalities will be commented and provide a @FIXME comment along with it. So that you can easily findout the necessary fixes that the DMU can't do.

Now enable your module and fix the issues in Drupal 8 syntax. Also note that your .info or other Drupal 7 supporting files will be there which can be easily removed after fix(if it has no use) and completely upgrading your module codes. Now test your code.

Happy Coding!



on 21st May 2013 / by Anoop John
Drupal 6 will be maintained till the release of Drupal 8. Drupal 8 release is expected to happen towards the end of 2013. The current stable branch Drupal 7 will be maintained till the release of Drupal 9 (probably 2015). If you are running a production site on Drupal 6 then you will probably have to start looking at upgrading the site by the end of this year. There are couple of different options open in front of you if you are looking to upgrade your Drupal 6 site soon. If the site does not use a lot of custom functionalities and uses minimal contributed module functionalities and you are not really interested in contributing towards migrating Drupal 7 modules to Drupal 8 then you could just go ahead and upgrade your Drupal 6 site to Drupal 7. This could be done anytime you have the budget to do this. If you are interested in contributing towards migrating Drupal 7 contrib modules to Drupal 8 then you could wait a bit and then migrate your Drupal 6 site into Drupal 8 by the time Drupal 8 is released. You could start on the work a few months before the release date of Drupal 8. If the site does have a lot of custom functionalities as opposed to contributed module functionalities then you should really be looking to migrate to Drupal 8. Work on this could be started as soon as we have an RC version of Drupal 8. You will however have to be prepared to contribute towards migrating some of the Drupal 7 modules to Drupal 8 as it would take a while before top 100 contributed modules have Drupal 8 versions. If you are not sure about which version of Drupal you should upgrade your site to do get in touch with us and we can help you make that decision for you. Do note that this is a time sensitive article written in May 2013 and the opinions cited in this article may not be relevant after a few months from writing this article. The concepts would still hold though. Contact us to get our recommendation on what version of Drupal should you be upgrading your site to. Drupal Drupal 6 Drupal Upgrade Drupal 7 Drupal 8 Leave a reply Your email address will not be published. Required fields are marker *

on 26th December 2014 / by abhai.sasidharan
YAML is a data serialization language which is easily readable to both humans and computers. It is for this very reason that YAML is being used in Drupal 8. YAML stands for YAML Ain't Markup Language. This is what a Drupal 8 module.info.yml file would look like : name: Zyx Module description: Zyx Module description. ;This is how you comment. Description field is mandatory. package: Custom type: module version: 1.0 core: 8.x dependencies: - node This is how a theme is defined in theme.info.yml file : name: Zyx type: theme description: 'A zyx theme.' package: Custom core: 8.x stylesheets: all: - css/layout.css print: - css/print.css stylesheets-remove: - normalize.css regions: header: Header content: Content sidebar_first: 'Sidebar first' footer: Footer This is how permissions are set in Drupal 8 YAML : # In views.permissions.yml file. access all views: title: 'Bypass views access control' description: 'Bypass access control when accessing views.' restrict access: TRUE This is how routing is set in Drupal 8 YAML : demo.page: path: /demo defaults: _title: 'Demo' _content: '\Drupal\demo\Controller\DefaultController::demo' requirements: _permission: 'access demo content' YAML files are parsed by Yaml.php in Drupal 8. It is a symfony component. Another reason to use YAML is because, .info files are Drupal specific and YAML is a created to provide data serialization. In Drupal 8, not just info files but permissions, routing and settings configuration are also defined in YAML format now. Earlies this was accomplished in the .module file. This makes the code more lean. To describe it in two words, compartmentalization and delegating. Drupal Drupal 8 Leave a reply Your email address will not be published. Required fields are marker *

on 29th December 2014 / by abhai.sasidharan
Drupal, up until now a PAC (Presentation Abstraction Control) architecture, has taken a step closer to MVC (Model View Controller) architecture. Although nowhere have they mentioned about MVC, the new Drupal 8 is strictly object oriented. Another feature in Drupal 8, that is different from the existing versions of Drupal is that it is not entirely Drupal. Drupal 8 uses many components in symfony like it's ClassLoader, YAML file structure, twig and so on. For a detailed description please visit the Drupal 8 home page. In this article, I will explain how to convert an existing Drupal 7 module to Drupal 8. In Drupal 7, the first steps you follow to create a module is Create a <module name>.info file Create a <module name>.module file Create a <module name>.install file if a schema is required These are the basic steps for a simple module creation. Plugins, css, images, etc can be added as required. This is basically the same in Drupal 8 except we have to follow a yaml file structure in Drupal 8. The <module name>.info file should be renamed as <module name>.info.yml. Say, for a module zyx, if the zyx.info file in Drupal 7 was : name = ZYX description = Some module to something. package = ZYX core = 7.x files[] = zyx.module files[] = zyx.install ; Information added by Drupal.org packaging script on 2013-12-12 version = "7.x-3.0" core = "7.x" project = "zyx" datestamp = "1386880109" In Drupal 8, the zyx.info.yml would be : name: ZYX description: 'Some module to something.' package: ZYX core: 8.x version: 7.x-3.0 project: zyx datestamp: '1386880109' type: module After the <module name>.info.yml file has been defined, you can go to the extend page in your Drupal site and see that the module has appeared in Drupal 8. The <module name>.install and <module name>.module files remain where they are. The schema definition remains unchanged in Drupal 8. The .module file has many changes which we will discuss now. Firstly, hook_menu has been replaced in Drupal 8 by another yml file called <module name>.routing.yml. This is also a requisite for Drupal 8 module. Clear the hook_menu and move it with corresponding yml syntax to the <module name>.routing.yml file in the root of the module folder : In Drupal 7 : <?php function zyx_menu() { $items = array(); $items['zyx/one'] = array( 'title' => 'Zyx entry', 'description' => 'Enter zyx info into database', 'page callback' => 'Drupal_get_form', 'page arguments' => array('zyx_form'), 'access arguments' => array('access zyx content'), 'type' => MENU_NORMAL_ITEM, ); } In Drupal 8 : zyx.routing.yml zyx.form: path: /zyx/one defaults: _title: 'Zyx entry' _form: \Drupal\zyx\Form\ZyxForm requirements: _permission: 'access zyx content' As you can see in the yml file, the path to the form is defined and we notice another difference, which is the form definition has been moved from the .module file to a class in the form folder. We have to create a folder structure in the module folder to implement the MVC part of Drupal 8 i.e., module/ src/ Controller/ Form/ !-- Each form should be in a separate ClassName.php file. If any. Plugin/ Block/ !-- If any. <module name>.module <module name>.routing.yml <module name>.menu.links.yml <module name>.info.yml <module name>.permissions.yml <module name>.install This is standard for all Drupal modules. This is the PSR-4 compatible folder structure (Confer with PSR documentation). The form should be defined in a php file in the Form folder. This is the controller for the form. An example would be, in this case, "ZyxForm.php". Delete the form definition in <module name>.module file and copy it into the controller class definition in the form folder making the changes like below. The form definition for this would be : <?php /** * @file * Contains \Drupal\zyx\Form\ZyxForm. */ namespace Drupal\zyx\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; class Zyx extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'zyx_form'; } public function buildForm(array $form, FormStateInterface $form_state) { $form['zyx_data'] = array( '#type' => 'textfield', '#title' => t('Data'), '#size' => 30, '#maxlength' => 200, '#description' => t('Zyx data.'), '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t($submit), ); return $form; } public function validateForm(array &$form, FormStateInterface $form_state) { //Code to validate here. Same as Drupal 7. } public function submitForm(array &$form, FormStateInterface $form_state) { //Code to submit here. Same as Drupal 7. } } Secondly, permissions are no longer set inside the .module file itself. You have to include a .permissions.yml file. In Drupal 7 : <?php /** * Implements hook_permission(). * * Access and view content defined. */ function zyx_permission() { return array( 'access zyx content' => array( 'title' => t('Access content for the Zyx module'), ), ); } In Drupal 8 : zyx.permissions.yml 'access zyx content': title: 'Access content for the Address book module' Thirdly, menu links are a separate file named <module name>.lniks.menu.yml unlike Drupal 8 which included it in the hook_menu itself. It is as follows : zyx.form: route_name: zyx.form title: 'Zyx Entry' description: 'Enter zyx info into database' parent: zyx.page Fourthly, any custom page defined in the <module name>.module will also have to be removed from the <module name>.module file. This will have to be moved to the controller folder as a Controller class similar to how form was done only difference is the class to extend : <?php /** * @file * Contains \Drupal\zyx\Controller\DefaultController. */ namespace Drupal\zyx\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Url; /** * Default controller for the zyx module. */ class ZyxController extends ControllerBase { //Custom page function(s) here. Copy the functions and from <module name>.module and place it here. } Finally, blocks are implemented as plugins in Drupal 8. If you look at the folder structure mentioned above, you can see that in the plugin folder there is block folder. This is because blocks are no longer defined in the conventional style; hook_block_info(), hook_block_view() have been deprecated. Your block definitions should be in another controller class similar to form. An example : ZyxChow.php <?php /** * @file * Contains \Drupal\zyx\Plugin\Block\ZyxChow. */ namespace Drupal\zyx\Plugin\Block; use Drupal\Core\Block\BlockBase; /** * Provides the ZyxChow block. * * @Block( * id = "zyx_chow", * admin_label = @Translation("Zyx's Chow") * ) */ class ZyxChow extends BlockBase { /** * {@inheritdoc} */ public function build() { // Code to create a block. Just like Drupal 7. //Return a renderable array; } } Here, the @block part in the comment section is a mandatory. It defines the machine name and name of the block. These are the basic things to be changed in a Drupal 7 module to make it work in a Drupal 8 installation. A few key things to remember while migrating to Drupal 8 are the PSR-4 folder compatibility, YAML file and correct syntax to use, all paths should be defined in routing YAML file. Migrating a module to Drupal 8 can be very long and tedious due to the vast differences from Drupal 7 to Drupal 8. There is another way to migrate modules to Drupal 8, which is using a Drupal 8 module called Drupal module upgrader. This module is in its development stages and does the converting fine for modules with a simple file structure, although it is found to be buggy when migrating projects with more than one modules like the coder or devel module. Resources: Drupal 7 to 8 Drupal Drupal 8 Leave a reply Your email address will not be published. Required fields are marker *
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.