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 new EntityTypeInterface::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

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Status: Active » Needs review
claudiu.cristea’s picture

claudiu.cristea’s picture

Fixed the ::getBundleOfEntityTypeIds() which should be nullable.

claudiu.cristea’s picture

Latest changes: Fixed ::getBundleOf() leftovers.

claudiu.cristea’s picture

Berdir’s picture

I'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.

amateescu’s picture

I have the same opinion as @Berdir, I don't think the additional complexity introduced here is worth it.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nod_’s picture

Status: Needs review » Closed (won't fix)

Seems the consensus is to not do what's proposed and there has been no updates in 2 years. Closing this.