Problem/Motivation
Right now, a bundle config entity type could serve as bundle only for one content entity type. E.g. node_type
is used for node
but cannot be used by a custom content entity type in the same time with node
. Some contrib/custom modules show that it's a real use-case to have a bundle config entity type shared across many content entity types. See the Entity Pilot case.
Recently, I hit a case when I need a new content entity type that extends taxonomy_term
. But I still want to use vocabulary
as bundle for the new entity type while it remains available for core, taxonomy_term
, term entity type. The two content entities should coexist and share the same bundle config entities.
The limitation is by design, as the bundle entity type bundle_of
annotation is a string rather than an array of strings.
Proposed resolution
- Replace the
EntityTypeInterface::getBundleOf()
with a newEntityTypeInterface::getBundleOfEntityTypeIds()
method that returns an array of content entity type IDs. - Deprecate
EntityTypeInterface::getBundleOf()
. - Deprecate declaring the
bundle_of
annotation as sting.
To be decided: How to resolve the field_ui_entity_operation()
case, where there the content entity type context lacks, so there's now way to figure out which is content the entity type to pick up.
Remaining tasks
Figure out how to handle the field_ui_entity_operation()
case.
User interface changes
None.
API changes
- New
EntityTypeInterface::getBundleOf()
method. EntityTypeInterface::getBundleOf()
is deprecated.- Declaring
bundle_of
annotation as sting is deprectaed.
Data model changes
None.
Release notes snippet
TBD.
Issue fork drupal-3191814
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
claudiu.cristeaComment #4
claudiu.cristeaAdding #2245763: Systematize fieldable bundlable as related issue.
Comment #5
claudiu.cristeaFixed the
::getBundleOfEntityTypeIds()
which should be nullable.Comment #6
claudiu.cristeaLatest changes: Fixed
::getBundleOf()
leftovers.Comment #7
claudiu.cristeaCR: https://www.drupal.org/node/3191815
Comment #8
BerdirI'm honestly not convinced this is worth it. Because there are cases where do need one, we end up having to introduce a new concept and definition for those cases. We end up deprecating a wildly used definition that affects a lot of modules and entity types for some what is IMHO a rare edge case.
All these are just convenience things, the actual API what bundles are is hook_entity_base_field_info() and that already supports anything to be defined as bundles.
Comment #9
amateescu CreditAttribution: amateescu as a volunteer commentedI have the same opinion as @Berdir, I don't think the additional complexity introduced here is worth it.
Comment #14
nod_Seems the consensus is to not do what's proposed and there has been no updates in 2 years. Closing this.