diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index 7efae87..a2d0781 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -36,11 +36,15 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang 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->getPropertyDefinitions() and - // $display->getComponents(). - foreach (array_intersect_key($entity->getPropertyDefinitions(), $displays[$entity->bundle()]->getComponents()) as $field_name => $field_info) { - foreach ($entity->get($field_name) as $item) { - $item->_attributes = array(); + // 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) { + if ($entity->getPropertyDefinition($name)) { + foreach ($entity->get($name) as $item) { + $item->_attributes = array(); + } } } }