diff --git a/core/includes/common.inc b/core/includes/common.inc
index dfd20fa..8f8ab08 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4039,7 +4039,7 @@ function drupal_render_cache_set(&$markup, $elements) {
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
$expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CacheBackendInterface::CACHE_PERMANENT;
- $tags = isset($elements['#cache']['tags']) ? $elements['#cache']['tags'] : array();
+ $tags = drupal_render_collect_cache_tags($elements, TRUE);
cache($bin)->set($cid, $data, $expire, $tags);
}
@@ -4087,6 +4087,57 @@ function drupal_render_collect_attached($elements, $return = FALSE) {
}
/**
+ * Collects cache tags for an element and its children into a single array.
+ *
+ * When caching elements, it is necessary to collect all cache tags into a
+ * single array, from both the element itself and all child elements. This
+ * allows items to be invalidated based on all tags attached to the content
+ * they're constituted from.
+ *
+ * @param array $elements
+ * The element to collect cache tags from.
+ * @param bool $return
+ * Whether to return the attached elements and reset the internal static.
+ *
+ * @return array
+ * The cache tags array for this element and its descendants.
+ */
+function drupal_render_collect_cache_tags($elements, $return = FALSE) {
+ $tags = &drupal_static(__FUNCTION__, array());
+
+ // Collect all cache tags for this element.
+ if (isset($elements['#cache']['tags'])) {
+ foreach ($elements['#cache']['tags'] as $namespace => $values) {
+ if (is_array($values)) {
+ foreach ($values as $value) {
+ if (!isset($tags[$namespace][$value])) {
+ $tags[$namespace][$value] = $value;
+ }
+ }
+ }
+ else {
+ if (!isset($tags[$namespace])) {
+ $tags[$namespace] = $values;
+ }
+ }
+ }
+ }
+ if ($children = element_children($elements)) {
+ foreach ($children as $child) {
+ drupal_render_collect_cache_tags($elements[$child]);
+ }
+ }
+
+ // If this was the first call to the function, return all attached elements
+ // and reset the static cache.
+ if ($return) {
+ $return = $tags;
+ $tags = array();
+ return $return;
+ }
+}
+
+/**
* Prepares an element for caching based on a query.
*
* This smart caching strategy saves Drupal from querying and rendering to HTML
diff --git a/core/includes/entity.inc b/core/includes/entity.inc
index fe30114..5f92cc1 100644
--- a/core/includes/entity.inc
+++ b/core/includes/entity.inc
@@ -48,6 +48,18 @@ function entity_info_cache_clear() {
}
/**
+ * Clears the entity render cache for all entity types.
+ */
+function entity_render_cache_clear() {
+ $entity_manager = Drupal::entityManager();
+ foreach ($entity_manager->getDefinitions() as $entity_type => $info) {
+ if ($entity_manager->hasController($entity_type, 'render')) {
+ $entity_manager->getRenderController($entity_type)->resetCache();
+ }
+ }
+}
+
+/**
* Returns the entity bundle info.
*
* @param string|null $entity_type
@@ -622,14 +634,19 @@ function entity_render_controller($entity_type) {
* @param string $langcode
* (optional) For which language the entity should be rendered, defaults to
* the current content language.
+ * @param bool $reset
+ * (optional) Whether to reset the render cache for the requested entity.
+ * Defaults to FALSE.
*
* @return array
* A render array for the entity.
*/
-function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL) {
- return Drupal::entityManager()
- ->getRenderController($entity->entityType())
- ->view($entity, $view_mode, $langcode);
+function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) {
+ $render_controller = Drupal::entityManager()->getRenderController($entity->entityType());
+ if ($reset) {
+ $render_controller->resetCache(array($entity));
+ }
+ return $render_controller->view($entity, $view_mode, $langcode);
}
/**
@@ -642,15 +659,20 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL) {
* @param string $langcode
* (optional) For which language the entity should be rendered, defaults to
* the current content language.
+ * @param bool $reset
+ * (optional) Whether to reset the render cache for the requested entities.
+ * Defaults to FALSE.
*
* @return array
* A render array for the entities, indexed by the same keys as the
* entities array passed in $entities.
*/
-function entity_view_multiple(array $entities, $view_mode, $langcode = NULL) {
- return Drupal::entityManager()
- ->getRenderController(reset($entities)->entityType())
- ->viewMultiple($entities, $view_mode, $langcode);
+function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $reset = FALSE) {
+ $render_controller = Drupal::entityManager()->getRenderController(reset($entities)->entityType());
+ if ($reset) {
+ $render_controller->resetCache($entities);
+ }
+ return $render_controller->viewMultiple($entities, $view_mode, $langcode);
}
/**
diff --git a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
index b8e4061..79e5c52 100644
--- a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
+++ b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php
@@ -138,6 +138,14 @@ class EntityType extends Plugin {
public $static_cache = TRUE;
/**
+ * Boolean indicating whether the rendered output of entities should be
+ * cached.
+ *
+ * @var bool (optional)
+ */
+ public $render_cache = TRUE;
+
+ /**
* Boolean indicating whether entities of this type have multilingual support.
*
* At an entity level, this indicates language support and at a bundle level
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 33a62ce..331a65e 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -349,7 +349,11 @@ public function getTranslationLanguages($include_default = TRUE) {
* Implements \Drupal\Core\Entity\EntityInterface::save().
*/
public function save() {
- return \Drupal::entityManager()->getStorageController($this->entityType)->save($this);
+ $return = \Drupal::entityManager()->getStorageController($this->entityType)->save($this);
+ if (\Drupal::entityManager()->hasController($this->entityType, 'render')) {
+ \Drupal::entityManager()->getRenderController($this->entityType)->resetCache(array($this));
+ }
+ return $return;
}
/**
@@ -358,6 +362,9 @@ public function save() {
public function delete() {
if (!$this->isNew()) {
\Drupal::entityManager()->getStorageController($this->entityType)->delete(array($this->id() => $this));
+ if (\Drupal::entityManager()->hasController($this->entityType, 'render')) {
+ \Drupal::entityManager()->getRenderController($this->entityType)->resetCache(array($this));
+ }
}
}
diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php
index cd92f52..54f8ca1 100644
--- a/core/lib/Drupal/Core/Entity/EntityRenderController.php
+++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php
@@ -6,9 +6,10 @@
*/
namespace Drupal\Core\Entity;
-use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
+use Drupal\Core\Entity\Plugin\DataType\EntityReferenceItem;
use Drupal\Core\Language\Language;
+use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
/**
* Base class for entity view controllers.
@@ -22,8 +23,37 @@ class EntityRenderController implements EntityRenderControllerInterface {
*/
protected $entityType;
+ /**
+ * The entity info array.
+ *
+ * @var array
+ *
+ * @see entity_get_info()
+ */
+ protected $entityInfo;
+
+ /**
+ * An array of view mode info for the type of entities for which this
+ * controller is instantiated.
+ *
+ * @var array
+ */
+ protected $viewModesInfo;
+
+ /**
+ * The cache bin used to store the render cache.
+ *
+ * @todo Defaults to 'cache' for now, until http://drupal.org/node/1194136 is
+ * fixed.
+ *
+ * @var string
+ */
+ protected $cacheBin = 'cache';
+
public function __construct($entity_type) {
$this->entityType = $entity_type;
+ $this->entityInfo = entity_get_info($entity_type);
+ $this->viewModesInfo = entity_get_view_modes($entity_type);
}
/**
@@ -62,6 +92,22 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco
'#view_mode' => $view_mode,
'#langcode' => $langcode,
);
+
+ // Cache the rendered output if permitted by the view mode settings.
+ $view_mode_is_cacheable = !isset($this->viewModesInfo[$view_mode]) || (isset($this->viewModesInfo[$view_mode]) && $this->viewModesInfo[$view_mode]['cache']);
+ if (!isset($entity->in_preview) && $this->entityInfo['render_cache'] && $view_mode_is_cacheable) {
+ $request = \Drupal::request();
+ $return['#cache'] = array(
+ 'keys' => array('entity_view', $this->entityType ,$entity->id(), $view_mode, $request->getQueryString()),
+ 'granularity' => DRUPAL_CACHE_PER_ROLE,
+ 'bin' => $this->cacheBin,
+ 'tags' => array(
+ $this->entityType . '_view' => TRUE,
+ $this->entityType => array($entity->id()),
+ ),
+ );
+ }
+
return $return;
}
@@ -164,4 +210,40 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
return $build;
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function resetCache(array $entities = NULL) {
+ if (isset($entities)) {
+ $tags = array();
+ foreach ($entities as $entity) {
+ $id = $entity->id();
+ $tags[$this->entityType][$id] = $id;
+
+ // @todo Remove when all entities are converted to EntityNG.
+ if (!$entity->getPropertyDefinitions()) {
+ continue;
+ }
+
+ // Add all the referenced entity types and IDs to the tags that will be
+ // cleared.
+ foreach ($entity->getProperties() as $name => $definition) {
+ if ($entity->get($name)->offsetGet(0) instanceof EntityReferenceItem && $field_values = $entity->get($name)->getValue()) {
+ foreach (array_filter($field_values) as $value) {
+ // @todo This looks very ugly, ask the Entity API people for a
+ // nicer way to do it.
+ $field_item_definition = $entity->get($name)->offsetGet(0)->getPropertyDefinitions();
+ $target_entity_type = $field_item_definition['entity']['constraints']['EntityType'];
+ $tags[$target_entity_type][$value['target_id']] = $value['target_id'];
+ }
+ }
+ }
+ }
+ \Drupal::cache($this->cacheBin)->deleteTags($tags);
+ }
+ else {
+ \Drupal::cache($this->cacheBin)->deleteTags(array($this->entityType . '_view' => TRUE));
+ }
+ }
}
diff --git a/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php
index 03ba014..eb8f41b 100644
--- a/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php
+++ b/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php
@@ -75,4 +75,13 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N
* be available for loading.
*/
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL);
+
+ /**
+ * Resets the entity render cache.
+ *
+ * @param array|null $entities
+ * (optional) If specified, the cache is reset for the given entities only.
+ */
+ public function resetCache(array $entities = NULL);
+
}
diff --git a/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml b/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml
index ebacec5..6c2a3d1 100644
--- a/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml
+++ b/core/modules/block/custom_block/config/entity.view_mode.custom_block.full.yml
@@ -1,4 +1,5 @@
id: custom_block.full
label: Full
status: '0'
+cache: '1'
targetEntityType: custom_block
diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php
index 45a85d9..5523696 100644
--- a/core/modules/block/lib/Drupal/block/BlockRenderController.php
+++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php
@@ -62,4 +62,10 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
return $build;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function resetCache(array $entities = NULL) {
+ // @todo Move block render caching logic to this controller?
+ }
}
diff --git a/core/modules/book/config/entity.view_mode.node.print.yml b/core/modules/book/config/entity.view_mode.node.print.yml
index fe45f50..6f7333f 100644
--- a/core/modules/book/config/entity.view_mode.node.print.yml
+++ b/core/modules/book/config/entity.view_mode.node.print.yml
@@ -1,4 +1,5 @@
id: node.print
label: Print
status: '0'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc
index 4998f83..9a913ee 100644
--- a/core/modules/comment/comment.pages.inc
+++ b/core/modules/comment/comment.pages.inc
@@ -81,6 +81,7 @@ function comment_reply(EntityInterface $node, $pid = NULL) {
// This is the case where the comment is in response to a node. Display the node.
elseif (user_access('access content')) {
$build['comment_node'] = node_view($node);
+ unset($build['comment_node']['#cache']);
}
// Should we show the reply box?
diff --git a/core/modules/comment/config/entity.view_mode.comment.full.yml b/core/modules/comment/config/entity.view_mode.comment.full.yml
index e48fbd7..abfc646 100644
--- a/core/modules/comment/config/entity.view_mode.comment.full.yml
+++ b/core/modules/comment/config/entity.view_mode.comment.full.yml
@@ -1,4 +1,5 @@
id: comment.full
label: Full comment
status: '0'
+cache: '1'
targetEntityType: comment
diff --git a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php
index c6b21f0..14585d6 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php
@@ -79,9 +79,10 @@ protected function alterBuild(array &$build, EntityInterface $comment, EntityDis
$is_threaded = isset($comment->divs)
&& variable_get('comment_default_mode_' . $comment->bundle(), COMMENT_MODE_THREADED) == COMMENT_MODE_THREADED;
- // Add 'new' anchor if needed.
+ // Add 'new' anchor and disable render cache if needed.
if (!empty($comment->first_new)) {
$prefix .= "\n";
+ unset($build['#cache']);
}
// Add indentation div or close open divs as needed.
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php
index f4ef8cf..f6d595c 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php
@@ -148,6 +148,8 @@ function testAnonymous() {
'post comments' => FALSE,
'skip comment approval' => FALSE,
));
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
+ \Drupal::entityManager()->getRenderController('comment')->resetCache();
$this->drupalGet('node/' . $this->node->nid);
$this->assertPattern('@
]*>Comments
@', 'Comments were displayed.');
$this->assertLink('Log in', 1, 'Link to log in was found.');
@@ -158,6 +160,8 @@ function testAnonymous() {
'post comments' => TRUE,
'skip comment approval' => TRUE,
));
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
+ \Drupal::entityManager()->getRenderController('comment')->resetCache();
$this->drupalGet('node/' . $this->node->nid);
$this->assertNoPattern('@]*>Comments
@', 'Comments were not displayed.');
$this->assertFieldByName('subject', '', 'Subject field found.');
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
index 0332dd7..efffc66 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php
@@ -268,6 +268,7 @@ function setCommentsPerPage($number) {
*/
function setCommentSettings($name, $value, $message) {
variable_set($name . '_article', $value);
+ \Drupal::entityManager()->getRenderController('comment')->resetCache();
// Display status message.
$this->pass($message);
}
diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php
index 99008e2..fa1276a 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php
@@ -126,7 +126,14 @@ public function save() {
if (empty($this->id)) {
$this->id = $this->id();
}
- return parent::save();
+ $return = parent::save();
+
+ // Reset the render cache for the target entity type.
+ if (\Drupal::entityManager()->hasController($this->targetEntityType, 'render')) {
+ \Drupal::entityManager()->getRenderController($this->targetEntityType)->resetCache();
+ }
+
+ return $return;
}
/**
diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
index 4fe2c12..074a448 100644
--- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
+++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php
@@ -57,4 +57,11 @@
*/
public $status = FALSE;
+ /**
+ * Whether or not the rendered output of this view mode is cached by default.
+ *
+ * @var bool
+ */
+ public $cache = TRUE;
+
}
diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php
index fa780a5..0ac08a7 100644
--- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php
+++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php
@@ -95,8 +95,21 @@ public function view(EntityInterface $entity, $langcode, array $items) {
'#object' => $entity,
'#items' => $items,
'#formatter' => $this->getPluginId(),
+ '#cache' => array('tags' => array())
);
+ // Gather cache tags from reference fields.
+ foreach ($items as $item) {
+ if (isset($item['format'])) {
+ $info['#cache']['tags']['filter_format'] = $item['format'];
+ }
+
+ if (isset($item['entity'])) {
+ $info['#cache']['tags'][$item['entity']->entityType()][] = $item['entity']->id();
+ $info['#cache']['tags'][$item['entity']->entityType() . '_view'] = TRUE;
+ }
+ }
+
$addition[$field_name] = array_merge($info, $elements);
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
index a5d8790..08690dc 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
@@ -346,6 +346,7 @@ function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $mes
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;
$element = node_view($clone, $view_mode);
+// $element = entity_view($clone, $view_mode, NULL, TRUE);
$output = drupal_render($element);
$this->verbose(t('Rendered node - view mode: @view_mode', array('@view_mode' => $view_mode)) . '
'. $output);
diff --git a/core/modules/file/config/entity.view_mode.file.full.yml b/core/modules/file/config/entity.view_mode.file.full.yml
index 60808f9..4d4ed1f 100644
--- a/core/modules/file/config/entity.view_mode.file.full.yml
+++ b/core/modules/file/config/entity.view_mode.file.full.yml
@@ -1,4 +1,5 @@
id: file.full
label: File default
status: '0'
+cache: '1'
targetEntityType: file
diff --git a/core/modules/node/config/entity.view_mode.node.full.yml b/core/modules/node/config/entity.view_mode.node.full.yml
index af6d938..e4d8bd0 100644
--- a/core/modules/node/config/entity.view_mode.node.full.yml
+++ b/core/modules/node/config/entity.view_mode.node.full.yml
@@ -1,4 +1,5 @@
id: node.full
label: Full content
status: '0'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/node/config/entity.view_mode.node.rss.yml b/core/modules/node/config/entity.view_mode.node.rss.yml
index 984b05f..0dbf7c1 100644
--- a/core/modules/node/config/entity.view_mode.node.rss.yml
+++ b/core/modules/node/config/entity.view_mode.node.rss.yml
@@ -1,4 +1,5 @@
id: node.rss
label: RSS
status: '0'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/node/config/entity.view_mode.node.teaser.yml b/core/modules/node/config/entity.view_mode.node.teaser.yml
index 2089b94..636de15 100644
--- a/core/modules/node/config/entity.view_mode.node.teaser.yml
+++ b/core/modules/node/config/entity.view_mode.node.teaser.yml
@@ -1,4 +1,5 @@
id: node.teaser
label: Teaser
status: '1'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/node/lib/Drupal/node/NodeRenderController.php b/core/modules/node/lib/Drupal/node/NodeRenderController.php
index a58a96f..1305bfd 100644
--- a/core/modules/node/lib/Drupal/node/NodeRenderController.php
+++ b/core/modules/node/lib/Drupal/node/NodeRenderController.php
@@ -85,6 +85,10 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityDisp
if (!empty($entity->nid)) {
$build['#contextual_links']['node'] = array('node', array($entity->nid));
}
+
+ // The node 'submitted' info is not rendered in a standard way (renderable
+ // array) so we have to add a cache tag manually.
+ $build['#cache']['tags']['user'][] = $entity->uid;
}
}
diff --git a/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php b/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php
index 4924f56..b43fc3c 100644
--- a/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/Views/RowPluginTest.php
@@ -137,6 +137,7 @@ public function testRowPlugin() {
// Test with links disabled.
$view->rowPlugin->options['links'] = FALSE;
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
$output = $view->preview();
$output = drupal_render($output);
$this->drupalSetContent($output);
@@ -146,6 +147,7 @@ public function testRowPlugin() {
// Test with links enabled.
$view->rowPlugin->options['links'] = TRUE;
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
$output = $view->preview();
$output = drupal_render($output);
$this->drupalSetContent($output);
@@ -155,6 +157,7 @@ public function testRowPlugin() {
// Test with comments enabled.
$view->rowPlugin->options['comments'] = TRUE;
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
$output = $view->preview();
$output = drupal_render($output);
foreach ($this->nodes as $node) {
@@ -165,6 +168,7 @@ public function testRowPlugin() {
// Test with comments disabled.
$view->rowPlugin->options['comments'] = FALSE;
+ \Drupal::entityManager()->getRenderController('node')->resetCache();
$output = $view->preview();
$output = drupal_render($output);
foreach ($this->nodes as $node) {
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 293c64e..017d6b9 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -621,13 +621,15 @@ function node_revision_delete($revision_id) {
* @see node_menu()
*/
function node_show(EntityInterface $node, $message = FALSE) {
+ // For markup consistency with other pages, use node_view_multiple() rather than node_view().
+ $nodes = array('nodes' => node_view_multiple(array($node->id() => $node), 'full'));
+
if ($message) {
drupal_set_title(t('Revision of %title from %date', array('%title' => $node->label(), '%date' => format_date($node->getRevisionCreationTime()))), PASS_THROUGH);
+ // Don't use the render cache when a revision is displayed.
+ unset($nodes['nodes'][$node->id()]['#cache']);
}
- // For markup consistency with other pages, use node_view_multiple() rather than node_view().
- $nodes = array('nodes' => node_view_multiple(array($node->id() => $node), 'full'));
-
// Update the history table, stating that this user viewed this node.
if (module_exists('history')) {
history_write($node->id());
@@ -1748,7 +1750,7 @@ function _node_index_node(EntityInterface $node) {
foreach ($languages as $language) {
// Render the node.
- $build = node_view($node, 'search_index', $language->id);
+ $build = entity_view($node, 'search_index', $language->langcode, TRUE);
unset($build['#theme']);
$node->rendered = drupal_render($build);
diff --git a/core/modules/search/config/entity.view_mode.node.search_index.yml b/core/modules/search/config/entity.view_mode.node.search_index.yml
index ed22c30..e12156d 100644
--- a/core/modules/search/config/entity.view_mode.node.search_index.yml
+++ b/core/modules/search/config/entity.view_mode.node.search_index.yml
@@ -1,4 +1,5 @@
id: node.search_index
label: Search index
status: '0'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/search/config/entity.view_mode.node.search_result.yml b/core/modules/search/config/entity.view_mode.node.search_result.yml
index 1608657..776ada9 100644
--- a/core/modules/search/config/entity.view_mode.node.search_result.yml
+++ b/core/modules/search/config/entity.view_mode.node.search_result.yml
@@ -1,4 +1,5 @@
id: node.search_result
label: Search result
status: '0'
+cache: '1'
targetEntityType: node
diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module
index 0c4580c..dbe529f 100644
--- a/core/modules/statistics/statistics.module
+++ b/core/modules/statistics/statistics.module
@@ -73,6 +73,17 @@ function statistics_node_view(EntityInterface $node, EntityDisplay $display, $vi
}
/**
+ * Implements hook_node_view_alter().
+ */
+function statistics_node_view_alter(&$build, EntityInterface $node, EntityDisplay $display) {
+ // If statistics were added to the node render array, we can't use the render
+ // cache.
+ if (isset($build['links']['statistics'])) {
+ unset($build['#cache']);
+ }
+}
+
+/**
* Implements hook_menu().
*/
function statistics_menu() {
diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php
index d3de481..ab4de83 100644
--- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php
+++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php
@@ -105,6 +105,7 @@ public function submitForm(array &$form, array &$form_state) {
foreach (config_get_storage_names_with_prefix('locale.config.' . $this->language->id . '.system.date_format.') as $config_id) {
$this->configFactory->get($config_id)->delete();
}
+ entity_render_cache_clear();
$form_state['redirect'] = 'admin/config/regional/date-time/locale';
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php
index b9752b4..ab4cb04 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php
@@ -65,6 +65,7 @@ function testTimeZoneHandling() {
// Set time zone to Los Angeles time.
$config->set('default', 'America/Los_Angeles')->save();
+ \Drupal::entityManager()->getRenderController('node')->resetCache(array($node1, $node2));
// Confirm date format and time zone.
$this->drupalGet("node/$node1->nid");
diff --git a/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.full.yml b/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.full.yml
index 8902bc3..4ce40f1 100644
--- a/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.full.yml
+++ b/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.full.yml
@@ -1,4 +1,5 @@
id: entity_test_render.full
label: Full
status: '0'
+cache: '1'
targetEntityType: entity_test_render
diff --git a/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.test.yml b/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.test.yml
index a0d108b..310bceb 100644
--- a/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.test.yml
+++ b/core/modules/system/tests/modules/entity_test/config/entity.view_mode.entity_test_render.test.yml
@@ -1,4 +1,5 @@
id: entity_test_render.test
label: Test
status: '0'
+cache: '1'
targetEntityType: entity_test_render
diff --git a/core/modules/taxonomy/config/entity.view_mode.taxonomy_term.full.yml b/core/modules/taxonomy/config/entity.view_mode.taxonomy_term.full.yml
index 100547e..2666012 100644
--- a/core/modules/taxonomy/config/entity.view_mode.taxonomy_term.full.yml
+++ b/core/modules/taxonomy/config/entity.view_mode.taxonomy_term.full.yml
@@ -1,4 +1,5 @@
id: taxonomy_term.full
label: Taxonomy term page
status: '0'
+cache: '1'
targetEntityType: taxonomy_term
diff --git a/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml b/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml
index bb47091..8961a6f 100644
--- a/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml
+++ b/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml
@@ -1,4 +1,5 @@
id: vocabulary.full
label: Taxonomy vocabulary
status: '0'
+cache: '1'
targetEntityType: taxonomy_vocabulary
diff --git a/core/modules/user/config/entity.view_mode.user.compact.yml b/core/modules/user/config/entity.view_mode.user.compact.yml
index c27265b..c211e99 100644
--- a/core/modules/user/config/entity.view_mode.user.compact.yml
+++ b/core/modules/user/config/entity.view_mode.user.compact.yml
@@ -1,4 +1,5 @@
id: user.compact
label: Compact
status: '1'
+cache: '1'
targetEntityType: user
diff --git a/core/modules/user/config/entity.view_mode.user.full.yml b/core/modules/user/config/entity.view_mode.user.full.yml
index ac1ca20..343e909 100644
--- a/core/modules/user/config/entity.view_mode.user.full.yml
+++ b/core/modules/user/config/entity.view_mode.user.full.yml
@@ -1,4 +1,5 @@
id: user.full
label: User account
status: '0'
+cache: '1'
targetEntityType: user
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
index f4a0662..280b645 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
@@ -121,6 +121,8 @@ function testPictureOnNodeComment() {
->set('features.node_user_picture', FALSE)
->set('features.comment_user_picture', FALSE)
->save();
+ \Drupal::entityManager()->getStorageController('node')->resetCache(array($node));
+ \Drupal::entityManager()->getStorageController('comment')->resetCache();
$this->drupalGet('node/' . $node->nid);
$this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');