Commit d562cd4b authored by alexpott's avatar alexpott

Issue #2556767 by Berdir, Wim Leers: Remove placeholdering of node links

parent f2c047c6
......@@ -41,7 +41,6 @@ public function buildComponents(array &$build, array $entities, array $displays,
$langcode,
!empty($entity->in_preview),
]],
'#create_placeholder' => TRUE,
);
}
......
......@@ -2,3 +2,4 @@ access_log:
enabled: false
max_lifetime: 259200
count_content_views: 0
display_max_age: 3600
......@@ -17,6 +17,9 @@ statistics.settings:
count_content_views:
type: integer
label: 'Count content views'
display_max_age:
type: integer
label: 'How long any statistics may be cached, i.e. the refresh interval'
block.settings.statistics_popular_block:
type: block_settings
......
......@@ -47,6 +47,9 @@ class StatisticsAdminTest extends WebTestBase {
protected function setUp() {
parent::setUp();
// Set the max age to 0 to simplify testing.
$this->config('statistics.settings')->set('display_max_age', 0)->save();
// Create Basic page node type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
......@@ -89,6 +92,16 @@ function testStatisticsSettings() {
$this->drupalGet('node/' . $this->testNode->id());
$this->client->post($stats_path, array('form_params' => $post));
$this->assertText('2 views', 'Node is viewed 2 times.');
// Increase the max age to test that nodes are no longer immediately
// updated, visit the node once more to populate the cache.
$this->config('statistics.settings')->set('display_max_age', 3600)->save();
$this->drupalGet('node/' . $this->testNode->id());
$this->assertText('3 views', 'Node is viewed 3 times.');
$this->client->post($stats_path, array('form_params' => $post));
$this->drupalGet('node/' . $this->testNode->id());
$this->assertText('3 views', 'Views counter was not updated.');
}
/**
......
......@@ -71,3 +71,11 @@ function statistics_update_8001() {
}
}
}
/**
* Disable the Statistics module if the node module is not enabled.
*/
function statistics_update_8002() {
// Set the new configuration setting for max age to the initial value.
\Drupal::configFactory()->getEditable('statistics.settings')->set('display_max_age', 3600)->save();
}
......@@ -50,6 +50,7 @@ function statistics_node_view(array &$build, EntityInterface $node, EntityViewDi
*/
function statistics_node_links_alter(array &$node_links, NodeInterface $entity, array &$context) {
if ($context['view_mode'] != 'rss') {
$node_links['#cache']['contexts'][] = 'user.permissions';
if (\Drupal::currentUser()->hasPermission('view post access counter')) {
$statistics = statistics_get($entity->id());
if ($statistics) {
......@@ -60,6 +61,7 @@ function statistics_node_links_alter(array &$node_links, NodeInterface $entity,
'#attributes' => array('class' => array('links', 'inline')),
);
}
$node_links['#cache']['max-age'] = \Drupal::config('statistics.settings')->get('display_max_age');
}
}
}
......
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