Slide 1

Slide 1 text

Prepare your modules for Drupal 9 João Ventura Senior Drupal Developer @ 1xINTERNET

Slide 2

Slide 2 text

João Ventura Account in d.o for 12 years and 3 months. Maintainer of some contrib modules (and themes) Co-organizer of: Drupal Dev Days Lisbon 2018 Drupal Europe 2018 Senior Developer at 1xINTERNET in Frankfurt (mostly remote from nearby Darmstadt) And yes, we’re hiring :)

Slide 3

Slide 3 text

“The big deal about Drupal 9 is … that it should not be a big deal.” Dries Buytaert, https://dri.es/plan-for-drupal-9

Slide 4

Slide 4 text

Drupal 9 What is it? Simply put, it will be Drupal 8.9: - all the deprecated APIs. + new versions of 3rd party libraries, like Symfony 4 or 5. Will be released in June 2020. Go see Gábor Hojtsy’s “State of Drupal 9” session yesterday.

Slide 5

Slide 5 text

Getting ready for D9 If you’re still in D7

Slide 6

Slide 6 text

Drupal 7 end of life You have 2 years, 4 months and 20 days

Slide 7

Slide 7 text

Drupal 7 end of life You have 2 years, 4 months and 20 days

Slide 8

Slide 8 text

Drupal 7 end of life You have 2 years, 4 months and 20 days Image adapted from Dries blog post at https://dri.es/drupal-7-8-and-9

Slide 9

Slide 9 text

“A journey of a thousand miles begins with a single step.” Laozi, Chapter 64 of the Tao Te Ching

Slide 10

Slide 10 text

Drupal 7 to 8 migrations D7 core (and friends) to D8 core It works! But... Ongoing work in meta issues: https://dgo.to/2456259 (non-i18n) https://dgo.to/2208401 (i18n) Multilingual entity_translation since 8/2018 Views are NOT migrated. They must be re-created in D8.

Slide 11

Slide 11 text

Upgrade Status module 7.x Availability information on Drupal 8 8.x Readyness for Drupal 9

Slide 12

Slide 12 text

https://www.drupal.org/project/drupalmoduleupgrader DMU tries to convert your D7 code to D8, based on common code conversion patterns. Creates routing.yml out of hook_menu(), module.info.yml out of module.info, src/Form/FormName.php out of configuration forms, etc. Run it: drush dmu-upgrade old_drupal7_module Not a magic wand! You’ll still have to do most of the work. Drupal 7 to 8 migrations Module not (yet) ported? Drupal module upgrader (DMU)

Slide 13

Slide 13 text

Search https://git.drupalcode.org/project/MODULE/ for migrations/d7_* files (or migration_templates) If files, are there, the module will provide some level of migration. If not, that functionality from your old site could in principle, be in the new site, but all your related current content/config may not go over to the new site, and will have to be re-created. Famous examples: metatag, webform, rules, captcha… (yes, and views) Solution? 1. Look in the issue queue. If not existing, create issue. 2. Work on it until RTBC. Drupal 7 to 8 migrations Module ported, but no d7->d8 migration Not even in the issue queue?

Slide 14

Slide 14 text

Drupal 7 to 8 migrations Pathauto example id: d7_pathauto_settings label: Pathauto configuration migration_tags: - Drupal 7 - Configuration source: plugin: variable variables: - pathauto_punctuation_ampersand - pathauto_punctuation_asterisk - pathauto_punctuation_at ... source_module: pathauto process: punctuation/ampersand: pathauto_punctuation_ampersand punctuation/asterisk: pathauto_punctuation_asterisk punctuation/at: pathauto_punctuation_at ... destination: plugin: config config_name: pathauto.settings id: d7_pathauto_patterns label: Pathauto patterns migration_tags: - Drupal 7 - Configuration source: plugin: pathauto_pattern constants: status: true ... process: status: constants/status id: id ... destination: plugin: 'entity:pathauto_pattern' migration_dependencies: optional: - d7_node_type

Slide 15

Slide 15 text

Drupal 7 to 8 migrations Useful modules In contrib: Migrate - base ELT system Migrate Drupal - base D6/7->D8 system Migrate Drupal UI - If wanted Migrate Drupal Multilingual - i18n support Migrate Plus - extra useful plugins Migrate Tools - migrate drush Migrate Upgrade - migrate drupal drush Migrate Devel - debug tools In core: drush si minimal drush pm:enable block_content config bootstrap content_translation migrate_drupal_ui migrate_upgrade ... drush then seven,bootstrap; drush cset system.theme default bootstrap; drush cset system.theme admin seven drush -y migrate:upgrade --legacy-db-key=drupal_7 --legacy-root=/var/www/drupal_7

Slide 16

Slide 16 text

In Drupal 8! Getting ready for Drupal 9

Slide 17

Slide 17 text

The best way to identify code deprecation at the moment is to use Upgrade Status if you want a UI, or drupal-check if using the command line. Get drupal-check here: https://github.com/mglaman/drupal-check Run it: drupal-check web/modules/contrib/MODULE It is a static analyser, which means you don’t need a running Drupal system to use it. Caveat: unlike PHP, we haven’t annotated Drupal core code with start of availability of APIs, so check if used APIs are available in latest supported D8 branch (currently 8.6) if creating contrib. Drupal 8 deprecated code (and how to find it)

Slide 18

Slide 18 text

We’re mostly getting rid of code that has been replaced by a better implementation. A lot of it is functional code. See deprecate meta issues for some examples of ongoing work: https://dgo.to/2999721 - Deprecate the legacy include files You should avoid calls to functions like file_managed_copy (already deprecated) or drupal_get_path (not yet). In alternative, try to open their implementation and use the replacement methods. Drupal 8 deprecated code (and how to guess what it will be)

Slide 19

Slide 19 text

A call to file_managed_copy('public://example.png', 'public://example1.png') can easily be replaced by \Drupal::service('file_system')->copy('public://example.png','public://example1.png') Why: function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { $file_system = \Drupal::service('file_system'); if (!isset($destination)) { … } return $file_system->copy($source, $destination, $replace); } catch (FileException $e) { return FALSE; } } Drupal 8 deprecated code (and how to get rid of it)

Slide 20

Slide 20 text

A call to drupal_get_path('module', 'token') can easily be replaced by dirname(\Drupal::service("extension.list.module")->getPathname('token')) Why: function drupal_get_path($type, $name) { return dirname(drupal_get_filename($type, $name)); } function drupal_get_filename($type, $name, $filename = NULL) { if ($type === 'core') {return 'core/core.info.yml';} try { $extension_list = \Drupal::service("extension.list.{$type}"); if (isset($filename)) { $extension_list->setPathname($name, $filename); } return $extension_list->getPathname($name); } catch (ServiceNotFoundException $e) { … } catch (\InvalidArgumentException $e) { … } } Drupal 8 deprecated code (and how to get rid of it)

Slide 21

Slide 21 text

Drupal 9 will ship with at least Symfony 4, but since Symfony 5.0 will be released in November 2019, we may jump from 3 to 5 directly. There is already some support for running Drupal 8 with Symfony 4 (and 5). See: https://dgo.to/2976394 - Allow Symfony 4 to be installed in Drupal 8 https://dgo.to/3055180 - Make Drupal 8 work with Symfony 5 (along with Symfony 3 and 4) You can have an early preview of how your site will behave in Drupal 9 by also applying the above patches. Or just wait until the Drupal 9.x branch starts to be used. This will probably happen late this year. Symfony 4 (and how to play with it)

Slide 22

Slide 22 text

JOIN US FOR CONTRIBUTION Drupal Dev Days Cluj 2019 Drupal 9 @drupaldevdays Migration D7 - D8 Contrib Migration

Slide 23

Slide 23 text

WHAT DID YOU THINK? Locate this session at the Drupal Developer Days Transylvania 2019 website: https://cluj2019.drupaldays.org/schedule Take the survey! https://www.surveymonkey.com/r/drupaltransylvania THANK YOU!