From 2b20dd205e1f129de71dc6f1369d49f19d40361b Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Sat, 6 Jun 2015 09:58:22 +0100 Subject: [PATCH] Issue #2500977 by olli: History module triggers a post request for anonymous users on all node pages --- core/modules/history/history.module | 15 +++++++++------ core/modules/history/src/Tests/HistoryTest.php | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/modules/history/history.module b/core/modules/history/history.module index e4dc165689..61def3e222 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -134,12 +134,15 @@ function history_cron() { */ function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) { // Update the history table, stating that this user viewed this node. - if (($display->getOriginalMode() === 'full') && \Drupal::currentUser()->isAuthenticated()) { - // When the window's "load" event is triggered, mark the node as read. - // This still allows for Drupal behaviors (which are triggered on the - // "DOMContentReady" event) to add "new" and "updated" indicators. - $build['#attached']['library'][] = 'history/mark-as-read'; - $build['#attached']['drupalSettings']['history']['nodesToMarkAsRead'][$node->id()] = TRUE; + if ($display->getOriginalMode() === 'full') { + $build['#cache']['contexts'][] = 'user.roles:authenticated'; + if (\Drupal::currentUser()->isAuthenticated()) { + // When the window's "load" event is triggered, mark the node as read. + // This still allows for Drupal behaviors (which are triggered on the + // "DOMContentReady" event) to add "new" and "updated" indicators. + $build['#attached']['library'][] = 'history/mark-as-read'; + $build['#attached']['drupalSettings']['history']['nodesToMarkAsRead'][$node->id()] = TRUE; + } } } diff --git a/core/modules/history/src/Tests/HistoryTest.php b/core/modules/history/src/Tests/HistoryTest.php index 62693ccbf4..3340f1a1fc 100644 --- a/core/modules/history/src/Tests/HistoryTest.php +++ b/core/modules/history/src/Tests/HistoryTest.php @@ -117,6 +117,7 @@ function testHistory() { // View the node. $this->drupalGet('node/' . $nid); + $this->assertCacheContext('user.roles:authenticated'); // JavaScript present to record the node read. $settings = $this->getDrupalSettings(); $libraries = explode(',', $settings['ajaxPageState']['libraries']); -- GitLab