EntityDisplayBase::getFieldDefinitions() checks that the $entity_type the Display applies to is Fieldable :

    // Entity displays are sometimes created for non-content entities.
    // @todo Prevent this in https://drupal.org/node/2095195.
    if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) {
      return array();
    }

That same check is performed in the __construct() :

    if (!$this->entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) {
      throw new \InvalidArgumentException('EntityDisplay entities can only handle content entity types.');
    }

- We could remove the check in getFieldDefinitions()
- Not sure why we check Fieldable. EntityDisplays should be about ContentEntities, but no reason to limit to those with fields.. OK, FieldableEntitiyInterface is larger than ContentEntityInterface. Then the exception message needs to be updated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.52 KB

Patch.

yched’s picture

Bump - easy RTBC ?

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Yes, looks good to me. I wasn't sure if it will conflict with #2248795: Entity displays fetch the bundle field definitions for deleted bundles, possibly, but we can always re-roll after one issue is in.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1: 2409661_EntityDisplay_duplicate_check-1.patch, failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.5 KB

Reroll

alexpott’s picture

Category: Task » Bug report
Status: Reviewed & tested by the community » Fixed

Duplicate code is a bug. This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed b524d3d and pushed to 8.0.x. Thanks!

  • alexpott committed b524d3d on 8.0.x
    Issue #2409661 by yched: Remove duplicate check for "FieldableEntity" in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.