Change record status: 
Project: 
Introduced in branch: 
9.4.x
Introduced in version: 
9.4.0
Description: 

It was possible to alter the label for bundles stored as config entities via hook_entity_bundle_info_alter(). Now altering label for config entity bundles via hook_entity_bundle_info_alter() is deprecated. If you need to alter the label for such bundles, use a different path:

  • The simplest way is to change the bundle entity label as is stored in database.
  • Implement hook_entity_load() or hook_ENTITY_TYPE_load().
  • Swap the bundle entity class and implement a custom ::label() method.

Before

function mymodule_entity_bundle_info_alter(array &$bundles) {
  // Change from 'Basic page' to 'Page'.
  $bundles['node']['page']['label'] = t('Page');
} 

After

NodeType::load('page')->set('name', 'Page')->save();

or

function mymodule_node_type_load($entities) {
  $entities['page']->set('name', 'Page');
}

or

function mymodule_entity_type_alter(array &$entity_types) {
  $entity_types['node_type']->setClass('Drupal\mymodule\MyNodeType');
}


class MyNodeType extends NodeType {
  public function label() {
     if ($this->name === 'page') {
       return 'Page';
     }
     return parent::label();
  }
}
Impacts: 
Module developers
Site templates, recipes and distribution developers