content_moderation_entity_bundle_field_info overrides the target bundle setting on the field definition for all bundles

Created on 29 August 2019, about 5 years ago
Updated 29 March 2023, over 1 year ago

Problem/Motivation

I’ve been searching for something else when I’ve seen content_moderation_entity_bundle_field_info(). I think that there might be a potential bug, because it does not clone the base field definition when setting the target bundle. I think that this might lead to overriding the target bundle setting for every bundle, because you’re re-using the reference to the original base field and not creating an unique object for each bundle.

Requesting the bundle fields for multiple bundles of the same entity type in a single request should demonstrate the problem.

An example for the correct implementation is \Drupal\taxonomy\Entity\Term::bundleFieldDefinitions().

Proposed resolution

Would it be possible to switch to the new FieldDefinition class - https://www.drupal.org/node/2982512 - and pass the base field definition to \Drupal\Core\Field\FieldDefinition::createFromFieldStorageDefinition()? This way we would not need to clone the base field anymore? I guess that we’ll also need an updated or a new CR describing this. Also to ensure no similar bugs occur we might start requiring from Drupal 9 that all objects returned by hook_entity_bundle_field_info() implementations are an instance of FieldDefinition and not BaseFieldDefinition.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

10.1

Component
Content moderation 

Last updated 1 day ago

Created by

🇩🇪Germany hchonov 🇪🇺🇩🇪🇧🇬

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024