Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291721

Bundle entity ::label() may return a different value than entity_type.bundle.info

$
0
0

Problem/Motivation

We use, for instance, NodeType::load('page')->label() to get a bundle's label. But there is also the entity_type.bundle.info, which acts like an entity bundle factory. In the case when hook_entity_bundle_info_alter() alters this label, NodeType::load('page')->label() will return a different value than \Drupal::service('entity_type.bundle.info')->getBundleInfo('node')['page']['label']. This might create confusion at API level as it's not clear which label getter is correct.

Steps to reproduce

A test to prove the bug https://www.drupal.org/pift-ci-job/1905506 (commit 740e84)

Proposed resolution

Deprecate the possibility to alter, in hook_entity_bundle_info_alter(), the label of a bundle defined as config entity. Third party code will have to use other methods to alter the bundle's label in such cases. Depending on the project several methods are available:

  • 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.

Disallow using hook_entity_bundle_info_alter() to alter labels of bundles stored as config entities in Drupal 10.0.0.

Remaining tasks

None.

User interface changes

None.

API changes

Using hook_entity_bundle_info_alter() to alter labels of bundles stored as config entities is deprecated in Drupal 9.2.0.

Data model changes

None.

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 291721

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>