diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index b544c02..ee5aa65 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -92,7 +92,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco // 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 ($this->entityInfo['render_cache'] && $view_mode_is_cacheable) { + if (!isset($entity->in_preview) && $this->entityInfo['render_cache'] && $view_mode_is_cacheable) { $return['#cache'] = array( 'keys' => array('entity_view', $this->entityType ,$entity->id(), $view_mode), 'granularity' => DRUPAL_CACHE_PER_ROLE, diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 0418b1d..882a7c1 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -203,6 +203,7 @@ function comment_admin_overview_submit($form, &$form_state) { } drupal_set_message(t('The update has been performed.')); $form_state['redirect'] = 'admin/content/comment'; + \Drupal::service('plugin.manager.entity')->getRenderController('comment')->resetCache(array($comment)); cache_invalidate_tags(array('content' => TRUE)); } @@ -250,8 +251,15 @@ function comment_multiple_delete_confirm($form, &$form_state) { */ function comment_multiple_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - comment_delete_multiple(array_keys($form_state['values']['comments'])); + $entity_manager = \Drupal::service('plugin.manager.entity'); + + $controller = $entity_manager->getStorageController('comment'); + $entities = $controller->load(array_keys($form_state['values']['comments'])); + $controller->delete($entities); + + $entity_manager->getRenderController('comment')->resetCache($entities); cache_invalidate_tags(array('content' => TRUE)); + $count = count($form_state['values']['comments']); watchdog('content', 'Deleted @count comments.', array('@count' => $count)); drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.')); @@ -310,6 +318,7 @@ function comment_confirm_delete_submit($form, &$form_state) { drupal_set_message(t('The comment and all its replies have been deleted.')); watchdog('content', 'Deleted comment @cid and its replies.', array('@cid' => $comment->id())); // Clear the cache so an anonymous user sees that his comment was deleted. + \Drupal::service('plugin.manager.entity')->getRenderController('comment')->resetCache(array($comment)); cache_invalidate_tags(array('content' => TRUE)); $form_state['redirect'] = "node/{$comment->nid->target_id}"; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8e9400f..a4426a2 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1987,6 +1987,7 @@ function comment_unpublish_by_keyword_action_submit($form, $form_state) { */ function comment_save_action(Comment $comment) { comment_save($comment); + \Drupal::service('plugin.manager.entity')->getRenderController('comment')->resetCache(array($comment)); cache_invalidate_tags(array('content' => TRUE)); watchdog('action', 'Saved comment %title', array('%title' => $comment->subject->value)); } diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index be4ef3f..5f1b780 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -80,6 +80,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? @@ -119,6 +120,7 @@ function comment_approve($cid) { if ($comment = comment_load($cid)) { $comment->status->value = COMMENT_PUBLISHED; comment_save($comment); + \Drupal::service('plugin.manager.entity')->getRenderController('comment')->resetCache(array($comment)); drupal_set_message(t('Comment approved.')); drupal_goto('node/' . $comment->nid->target_id); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 7c42a5b..c9f4f79 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -232,6 +232,7 @@ function testImageFieldDefaultImage() { $this->drupalPost("admin/structure/types/manage/article/fields/$field_name/field-settings", $edit, t('Save field settings')); // Clear field info cache so the new default image is detected. field_info_cache_clear(); + \Drupal::service('plugin.manager.entity')->getRenderController('node')->resetCache(array($node)); $field = field_info_field($field_name); $image = file_load($field['settings']['default_image']); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); diff --git a/core/modules/node/lib/Drupal/node/NodeRenderController.php b/core/modules/node/lib/Drupal/node/NodeRenderController.php index 6a6608a..5973fbd 100644 --- a/core/modules/node/lib/Drupal/node/NodeRenderController.php +++ b/core/modules/node/lib/Drupal/node/NodeRenderController.php @@ -91,6 +91,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/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index 46244b8..8209071 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -139,6 +139,7 @@ function testRevisions() { $new_node_revision->setNewRevision(); $new_node_revision->isDefaultRevision = FALSE; node_save($new_node_revision); + \Drupal::service('plugin.manager.entity')->getRenderController('node')->resetCache(array($node)); $this->drupalGet("node/$node->nid"); $this->assertNoText($new_body, 'Revision body text is not present on default version of node.'); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 36dcfe0..155c863 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1083,16 +1083,18 @@ 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->revision_timestamp))), 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->nid => $node), 'full')); - // Update the history table, stating that this user viewed this node. if (module_exists('history')) { - history_write($node->nid); + history_write($node->id()); } return $nodes; @@ -2247,7 +2249,7 @@ function _node_index_node(EntityInterface $node) { foreach ($languages as $language) { // Render the node. - $build = node_view($node, 'search_index', $language->langcode); + $build = entity_view($node, 'search_index', $language->langcode, TRUE); unset($build['#theme']); $node->rendered = drupal_render($build); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php index dbdba31..23d930f 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CommentAttributesTest.php @@ -285,6 +285,7 @@ function saveComment($nid, $uid, $contact = NULL, $pid = 0) { $comment = entity_create('comment', $values); $comment->save(); + \Drupal::service('plugin.manager.entity')->getRenderController('comment')->resetCache(array($comment)); return $comment; } } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 66842a5..4609517 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/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index c867581..a469c75 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::service('plugin.manager.entity')->getRenderController('node')->resetCache(array($node1, $node2)); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 2d45a62..47d4dd8 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2999,6 +2999,7 @@ function system_date_format_localize_reset_form($form, &$form_state, $langcode) function system_date_format_localize_reset_form_submit($form, &$form_state) { config('locale.config.' . $form['langcode']['#value'] . '.system.date') ->delete(); + entity_render_cache_clear(); $form_state['redirect'] = 'admin/config/regional/date-time/locale'; }