Commit 2b20dd20 authored by catch's avatar catch

Issue #2500977 by olli: History module triggers a post request for anonymous...

Issue #2500977 by olli: History module triggers a post request for anonymous users on all node pages
parent fbeaa7ee
...@@ -134,12 +134,15 @@ function history_cron() { ...@@ -134,12 +134,15 @@ function history_cron() {
*/ */
function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) { function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
// Update the history table, stating that this user viewed this node. // Update the history table, stating that this user viewed this node.
if (($display->getOriginalMode() === 'full') && \Drupal::currentUser()->isAuthenticated()) { if ($display->getOriginalMode() === 'full') {
// When the window's "load" event is triggered, mark the node as read. $build['#cache']['contexts'][] = 'user.roles:authenticated';
// This still allows for Drupal behaviors (which are triggered on the if (\Drupal::currentUser()->isAuthenticated()) {
// "DOMContentReady" event) to add "new" and "updated" indicators. // When the window's "load" event is triggered, mark the node as read.
$build['#attached']['library'][] = 'history/mark-as-read'; // This still allows for Drupal behaviors (which are triggered on the
$build['#attached']['drupalSettings']['history']['nodesToMarkAsRead'][$node->id()] = TRUE; // "DOMContentReady" event) to add "new" and "updated" indicators.
$build['#attached']['library'][] = 'history/mark-as-read';
$build['#attached']['drupalSettings']['history']['nodesToMarkAsRead'][$node->id()] = TRUE;
}
} }
} }
......
...@@ -117,6 +117,7 @@ function testHistory() { ...@@ -117,6 +117,7 @@ function testHistory() {
// View the node. // View the node.
$this->drupalGet('node/' . $nid); $this->drupalGet('node/' . $nid);
$this->assertCacheContext('user.roles:authenticated');
// JavaScript present to record the node read. // JavaScript present to record the node read.
$settings = $this->getDrupalSettings(); $settings = $this->getDrupalSettings();
$libraries = explode(',', $settings['ajaxPageState']['libraries']); $libraries = explode(',', $settings['ajaxPageState']['libraries']);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment