diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 71d3839..bb375ad 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -93,8 +93,10 @@ public static function createInstance(ContainerInterface $container, EntityTypeI public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) { $entities_by_bundle = array(); foreach ($entities as $id => $entity) { - // Remove previously built content, if exists. - $entity->content = array( + if (empty($entity->content)) { + $entity->content = array(); + } + $entity->content += array( '#view_mode' => $view_mode, ); // Initialize the field item attributes for the fields being displayed. @@ -195,11 +197,11 @@ public function entityViewBuilderPreRender(array $elements) { $this->moduleHandler->alter('entity_view_mode', $view_mode, $entity, $context); // Get the corresponding display settings. - $display = EntityViewDisplay::collectRenderDisplays($entity, $view_mode); + $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); // Build field renderables. $entity->content = $elements; - $this->buildContent(array($entity), array($bundle => $display), $view_mode, $langcode); + $this->buildContent(array($entity->id() => $entity), array($bundle => $display), $view_mode, $langcode); $view_mode = isset($entity->content['#view_mode']) ? $entity->content['#view_mode'] : $view_mode; $this->moduleHandler()->invokeAll($view_hook, array($entity, $display, $view_mode, $langcode)); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0070378..51d0561 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1312,17 +1312,14 @@ function comment_preview(CommentInterface $comment, array &$form_state) { // includes the comment reply form, which contains the comment preview and // therefore the rendered parent entity. This results in an infinite loop of // parent entity output rendering the comment form and the comment form - // rendering the parent entity. To prevent this infinite loop we temporarily - // set the value of the comment field on the rendered entity to hidden + // rendering the parent entity. To prevent this infinite loop we clone + // the commented entity and change the value of the comment field to hidden // before calling entity_view(). That way when the output of the commented - // entity is rendered, it excludes the comment field output. As objects are - // always addressed by reference we ensure changes are not lost by setting - // the value back to its original state after the call to entity_view(). + // entity is rendered, it excludes the comment field output. + $entity = clone $entity; $field_name = $comment->getFieldName(); - $original_status = $entity->get($field_name)->status; $entity->get($field_name)->status = COMMENT_HIDDEN; $build = entity_view($entity, 'full'); - $entity->get($field_name)->status = $original_status; } $preview_build['comment_output_below'] = $build;