DefaultSelection::createNewEntity() assumes entity type has a bundle key

Created on 27 October 2016, almost 9 years ago
Updated 27 August 2025, 23 days ago

Problem/Motivation

Over in #2766187: Allow config entity references β†’ , it has been discovered that \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::createNewEntity() assumes that the new entity type will have a bundle key.

This code:

    $bundle_key = $entity_type->getKey('bundle');
    $label_key = $entity_type->getKey('label');

    $entity = $this->entityManager->getStorage($entity_type_id)->create(array(
      $bundle_key => $bundle,
      $label_key => $label,
    ));

when used with an entity type that has no bundle key (eg, a config entity for instance) results in an error.

Proposed resolution

Only pass on the bundle key and value if the entity type has a bundle key.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Since there has been no activity here for over 8 years we are asking if this problem persists on a currently supported version of Drupal. To help, add a comment explaining if the problem still occurs or not. Any extra detail you can provide can help others who experienced this.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
    Thanks!

Production build 0.71.5 2024