diff --git b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 5231f3a..7550ad4 100644 --- b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -112,8 +112,9 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang module_invoke_all('entity_prepare_view', $this->entityType, $entities, $displays, $view_mode); foreach ($entities as $entity) { + // The content property may be null if no hook_view implementation added + // renderable content before this point. $entity->content = (!empty($entity->content)) ? $entity->content : array(); - // Remove previously built content, if exists. $entity->content += array( '#view_mode' => $view_mode, ); @@ -134,7 +135,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang * * @return array */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full', $langcode) { + protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { $that = $this; // Create a closure that uses the current execution context object as its // invocation object. @@ -192,8 +193,12 @@ public function entityViewBuilderPreRender(array $elements) { \Drupal::moduleHandler()->invokeAll($view_hook, array($entity, $display, $view_mode, $langcode)); \Drupal::moduleHandler()->invokeAll('entity_view', array($entity, $display, $view_mode, $langcode)); + // Build field renderables. $this->buildContent(array($entity), array($bundle => $display), $view_mode, $langcode); + // Do not override $build = $elements because hook_view implementations + // are expected to add content, not alter it. For example, mymodule_view + // should not change the #theme key. $build += $entity->content; // We don't need duplicate rendering info in $entity->content. unset($entity->content);