Upgrading Your Modules to Drupal 8 (DrupalCon Portland Session Notes)

Wayne Eaker
Module Developers
Upgrading Your Modules to Drupal 8 (DrupalCon Portland Session Notes)

When should you upgrade your modules?

  • Now: you can still suggest changes to the API
  • Wait until beta or RC: Will have less rework. (Beta/RC will be later this summer)

Pants Module

  • Example module to show how to do module updates.
  • Module Page: http://drupal.org/project/pants

Steps in Updating a Module

  • If you have tests in your Drupal 7 module, that will make it easier to find out what breaks as you update.
  • Use http://drupal.org/list-changes to find changes in D8 when looking for why your module doesn't work.
  • Your .info file needs to change to .info.yml. Change to YAML format and get rid of any files[] entries.
  • Enable the module, run your automated tests. (or test manually if you don't have tests)
  • Tests have to go in a specific directory, one class per file to meet PSR-0 standard.
  • Test base classes also have to be included with "use".

system_config_form()

  • system_settings_form() no longer exists. Use config() and system_config_form() instead.
  • Have to write a submit handler for system_config_form(), unlink system_settings_form().

Blocks

  • They are now plugins. You make a class that contains code that used to be in block_view(). The class method is blockBuild().
  • hook_block_info code is now an annotation on the class.

Menu Routers

  • Right now there's a backwards compatibility layer, but that's going away.
  • You need to switch over to the new route system.
  • Routing YAML file and controller classes to handle the "callbacks".
  • Use {} instead of % for wildcard arguments.

Forms

  • Config forms are now classes that extend SystemConfigFormBase.

Twig as Templating Engine

  • tpl.php files become .html.twig files.