-
-
Notifications
You must be signed in to change notification settings - Fork 68
Deprecation Error Solutions
Listed here are common deprecation errors and their solutions. Before replacing the deprecated call, confirm that the version of Drupal you are using does in fact have the newer approach available.
IMPORTANT! The examples below are proof of concept. Specific resolution may vary and always use dependency injection where possible.
Use the Messenger service instead. See core/includes/bootstrap.inc#L485, https://www.drupal.org/node/2774931, and core/lib/Drupal/Core/Messenger/Messenger.php for details.
Before
drupal_set_message($message, $type, $repeat);
After
\Drupal::messenger()->addMessage($message, $type, $repeat);
Use the entity type manager instead. See https://www.drupal.org/node/3033656 for details.
Before
$build = entity_view($node, 'teaser')
After
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node, 'teaser');
Use the entity type manager instead. Refer to https://git.drupalcode.org/project/drupal/blob/8.8.x/core/includes/entity.inc#L443 for details.
Before
entity_get_display($entity_type, $bundle, $view_mode);
After
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load($entity_type . '.' . $bundle . '.' . $view_mode);
Use the entity type manager instead. Refer to https://git.drupalcode.org/project/drupal/blob/8.8.x/core/includes/entity.inc#L523 for details.
Before
entity_get_form_display($entity_type, $bundle, $form_mode);
After
\Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($entity_type . '.' . $bundle . '.' . $form_mode);
Refer to core/tests/Drupal/KernelTests/AssertLegacyTrait.php for the correct method to use. For example, use assertEquals
instead of assertEqual
.
Refer to core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php for the correct method to use. For example, use elementExists
instead of assertElementPresent
.
For other messages, if you are using PHPStorm you can right click on the function call that is causing the error and go to its declaration to see information about why it is deprecated and what the resolution is.