Preparing for

Drupal 9

Sascha Grossenbacher

https://slides.com/saschagrossenbacher/drupal9

 

drupalmountaincamp.ch

What awesome new features will Drupal 9.0 have?

None.

(Almost none)

But there will be new features in 8.7, 8.8, 8.9...

Drupal 9.0 will...

  • Update dependencies (Symfony 4/5, Twig 2)
  • Remove backwards-compatibility layers
  • So that we can again add new features in 9.1, 9.2, ...

Why Drupal 9?

 

Symfony 3 EOL

 

Cost of deprecated code

300 Legacy Tests

 

https://dri.es/drupal-7-8-and-9

* Yes, old image

*

Drupal 9 Release plan

 

https://dri.es/plan-for-drupal-9

* Yes, old image

*

https://dri.es/drupal-7-8-and-9

Same EOL for Drupal 7 and 8

Why should I migrate now?

6/7 -> 8

  • Requires a content migration.
  • Options
    • A: 1:1 Migration, only well supported for core
    • B: New site, custom migration
  • => Requires time and $$$

8 -> 9

  • Regular update
  • 8.latest == Drupal 9 - deprecated code
  • "Only" API updates
  • New features in 8.x release
    • Media
    • Moderation/Workflows
    • Layouts

@deprecated

/**
  * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.
  *   Use EntityTypeManagerInterface::getDefinition() instead.
  *   See https://www.drupal.org/node/2549139.
  */
 public function getDefinition() {


@trigger_error()

For automated test and (maybe, later) also per-site logging.

@trigger_error("format_date() is deprecated in Drupal 8.0.0 and will
  be removed before Drupal 9.0.0. Use \Drupal::service('date.formatter')->format()   
  instead. See https://www.drupal.org/node/1876852", 
E_USER_DEPRECATED);
OK (2 tests, 108 assertions)

Remaining deprecation notices (1)

  1x: The property entityManager (entity.manager service) is deprecated in 
      Drupal\views\Plugin\views\row\EntityRow and will be removed before Drupal 9.0.0.
    1x in AggregatorRenderingTest::testFeedPage from Drupal\Tests\aggregator\Functional

How to update deprecated code

Option 1: Look at the deprecated function

function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
  return \Drupal::service('date.formatter')->format($timestamp, $type, $format, $timezone, $langcode);
}

Option 2: Look at the change record

 

https://www.drupal.org/node/1876852

Test for deprecations in contrib modules

Example Deprecations

Entity Manager

Pre-Split (8.0.0-rc2)

 

1500 Lines of Code

50 public methods

1700 LoC Unit Test

 

Basically the single API of the (large) entity system

Post-Split

 

EntityTypeManager

EntityFieldManager

EntityTypeRepository

EntityRepository

EntityDisplayRepository

EntityTypeBundleInfo

Several Listeners

Deprecated functions

db_*()

 

format_date()

 

file_*()

 

entity_*()

 

 

 

....

\Drupal::database()->...()

 

$date_formatter->format()

 

$file_system->...()

 

$entity_storage->...()
$EntityClass::...()

 

 

...

 

Entity methods

$entity->url()

 

$entity->link()

 

$file->url()

 

file_transform_relative($file->url())

 

 

 

....

$entity->toUrl()->toString()

 

$entity->toLink()->toString()

 

$file->createFileUrl(FALSE)

 

$file->createFileUrl()

SimpleTest

Custom Fork of Simpletest

project

 

Added 11 years ago to Drupal

 

KernelTestBase

WebTestBase

 

src/Tests

PHPUnit

Well-Known PHP components: PHPUnit, Mink, Selenium

 

KernelTestBase

UnitTestCase

BrowserTestBase

WebDriverTestBase

Nightwatch

 

tests/src/$TestType

How can I help?

Remove deprecated code in core

  • 699 @deprecated vs 440 @trigger_error() in core
  • Some are a lot of work: EntityManager deprecated in 8.0. 8.6 still had 1300 usages.
  • Good beginner issues
  • Deprecation policy
    • No deprecated code usages allowed for new deprecations
    • Before new @trigger_error() can be added, all usages must be updated.
    • But: some existing ones are excluded currently, many have no @trigger_error() yet

Get started

Pick a contributed module

  • Create an issue with the Deprecation-Patch
  • Fix the problems, same issue or split in dedicated issues if too much

Update tests to PHPUnit

  • All tests need to be converted to PHPUnit
    • Last Drupal core conversion yesterday: http://simpletest-countdown.org/
    • Move from $module/src/Tests to $module/tests/src/$type, update namespace
    • Update base class
    • Challenge: JS tests
      • drupalPostAjaxForm() is a lie

Questions?

Made with Slides.com