diff --git a/core/includes/common.inc b/core/includes/common.inc index a22764b..594405d 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3906,6 +3906,9 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; $elements['#markup'] = $prefix . $elements['#children'] . $suffix; + // Collect all #post_render_cache callbacks associated with this element when: + // - about to store this element in the render cache, or when; + // - about to apply #post_render_cache callbacks. if (!$is_recursive_call || isset($elements['#cache'])) { $post_render_cache = drupal_render_collect_post_render_cache($elements); if ($post_render_cache) { @@ -4161,6 +4164,13 @@ function drupal_render_cache_generate_placeholder($callback, array $context, $to } /** + * Generates a unique token for use in a render cache placeholder. + */ +function drupal_render_cache_generate_token() { + return \Drupal\Component\Utility\Crypt::randomBytesBase64(55); +} + +/** * Pre-render callback: Renders a render cache placeholder into #markup. * * @param $elements diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index c4b4570..685039c 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -123,7 +123,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang foreach ($entities_by_bundle as $bundle => $bundle_entities) { $build = $displays[$bundle]->buildMultiple($bundle_entities); foreach ($bundle_entities as $id => $entity) { - $entity->content = NestedArray::mergeDeepArray(array($entity->content, array('#view_mode' => $view_mode,), $build[$id],), TRUE); + $entity->content = NestedArray::mergeDeepArray(array($entity->content, array('#view_mode' => $view_mode), $build[$id]), TRUE); } } } @@ -143,7 +143,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang */ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { // Allow modules to change the view mode. - $this->moduleHandler->alter('entity_view_mode', $view_mode, $entity, $context); + $this->moduleHandler->alter('entity_view_mode', $view_mode, $entity, array('langcode' => $langcode)); $return = array( '#theme' => $this->entityTypeId, @@ -209,7 +209,6 @@ public function entityViewBuilderBuildView(array $elements) { $view_hook = "{$this->entityTypeId}_view"; $view_mode = $elements['#view_mode']; $langcode = $elements['#langcode']; - $context = array('langcode' => $langcode); // Get the corresponding display settings. $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); @@ -291,7 +290,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $entity = $this->entityManager->getTranslationFromContext($entity, $langcode); $entities[$key] = $entity; - //$build[$key] = $entity->content; $build[$key] = array( '#entity' => $entity ); diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index 3c09e51..ab2cc06 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -124,7 +124,6 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang $entity->content['#entity'] = $entity; $entity->content['#theme'] = 'comment__' . $entity->getFieldId() . '__' . $commented_entity->bundle(); $callback = '\Drupal\comment\CommentViewBuilder::renderLinks'; - $token = \Drupal\Component\Utility\Crypt::randomBytesBase64(55); $context = array( 'comment_entity_id' => $entity->id(), 'view_mode' => $view_mode, @@ -132,7 +131,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang 'commented_entity_type' => $commented_entity->getEntityTypeId(), 'commented_entity_id' => $commented_entity->id(), 'in_preview' => !empty($entity->in_preview), - 'token' => $token, + 'token' => drupal_render_cache_generate_token(), ); $entity->content['links'] = array( '#post_render_cache' => array( diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 9a71647..23756ed 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -167,7 +167,7 @@ public function viewElements(FieldItemListInterface $items) { 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), 'field_name' => $field_name, - 'token' => \Drupal\Component\Utility\Crypt::randomBytesBase64(55), + 'token' => drupal_render_cache_generate_token(), ); $output['comment_form'] = array( '#post_render_cache' => array( diff --git a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php index 448766f..7fac01f 100644 --- a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php @@ -35,13 +35,12 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang $display = $displays[$bundle]; $callback = '\Drupal\node\NodeViewBuilder::renderLinks'; - $token = \Drupal\Component\Utility\Crypt::randomBytesBase64(55); $context = array( 'node_entity_id' => $entity->id(), 'view_mode' => $view_mode, 'langcode' => $langcode, 'in_preview' => !empty($entity->in_preview), - 'token' => $token, + 'token' => drupal_render_cache_generate_placeholder(), ); $entity->content['links'] = array(