EntityViewBuilder::getBuildDefaults doesn't respect the EntityInterface of the $entity parameter

Created on 9 March 2018, almost 7 years ago
Updated 10 June 2024, 7 months ago

Problem/Motivation

The EntityViewBuilder::getBuildDefaults has an $entity parameter that should respect the EntityInterface.

Yet in the getBuildDefaults() method there's a call on the $entity object to a method that's not on the EntityInterface:

$entity->isDefaultRevision();

isDefaultRevision() lives on the ContentEntityBase but EntityViewBuilder might be used by a ConfigEntityBase.

This may result in an error Error: Call to undefined method Drupal\my_module\Entity\MyConfigEntity::isDefaultRevision() in EntityViewBuilder.php on line 181

Proposed resolution

We should check if the entity is an instance of RevisionableInterface first:

$entity instanceof RevisionableInterface
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 12 hours ago

Created by

🇧🇪Belgium mpp

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.

Sign in to follow issues

Merge Requests

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