diff -u b/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php --- b/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -34,9 +34,17 @@ // Initialize the field item attributes for the fields set to be displayed. foreach ($entities as $entity) { + // The entity can include fields that aren't displayed, and the display + // can include components that aren't fields, so we want to iterate the + // intersection of $entity->getProperties() and $display->getComponents(). + // However, the entity can have many more fields than are displayed, so we + // avoid the cost of calling $entity->getProperties() by iterating the + // intersection as follows. foreach ($displays[$entity->bundle()]->getComponents() as $name => $options) { - foreach ($entity->get($name) as $item) { - $item->_attributes = array(); + if ($entity->getPropertyDefinition($name)) { + foreach ($entity->get($name) as $item) { + $item->_attributes = array(); + } } } }