Commit 99088f65 authored by catch's avatar catch

Issue #2489966 by plach: The Views table style plugin does not specify cache...

Issue #2489966 by plach: The Views table style plugin does not specify cache contexts for click sorting
parent 8759ddca
......@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\CacheablePluginInterface;
use Drupal\views\Plugin\views\wizard\WizardInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
......@@ -27,7 +28,7 @@
* display_types = {"normal"}
* )
*/
class Table extends StylePluginBase {
class Table extends StylePluginBase implements CacheablePluginInterface {
/**
* Does the style plugin for itself support to add fields to it's output.
......@@ -428,5 +429,28 @@ public function wizardSubmit(&$form, FormStateInterface $form_state, WizardInter
}
}
/**
* {@inheritdoc}
*/
public function isCacheable() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
$contexts = [];
foreach ($this->options['info'] as $field_id => $info) {
if (!empty($info['sortable'])) {
$contexts[] = 'url.query_args:order';
$contexts[] = 'url.query_args:sort';
break;
}
}
return $contexts;
}
}
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\views\Views;
/**
......@@ -20,6 +21,8 @@
*/
class FieldWebTest extends HandlerTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* Views used by this test.
*
......@@ -62,11 +65,21 @@ protected function viewsData() {
public function testClickSorting() {
$this->drupalGet('test_click_sort');
$this->assertResponse(200);
// Only the id and name should be click sortable, but not the name.
$this->assertLinkByHref(\Drupal::url('view.test_click_sort.page_1', [], ['query' => ['order' => 'id', 'sort' => 'asc']]));
$this->assertLinkByHref(\Drupal::url('view.test_click_sort.page_1', [], ['query' => ['order' => 'name', 'sort' => 'desc']]));
$this->assertNoLinkByHref(\Drupal::url('view.test_click_sort.page_1', [], ['query' => ['order' => 'created']]));
// Check that the view returns the click sorting cache contexts.
$expected_contexts = [
'languages:language_interface',
'theme',
'url.query_args:order',
'url.query_args:sort',
];
$this->assertCacheContexts($expected_contexts);
// Clicking a click sort should change the order.
$this->clickLink(t('ID'));
$this->assertLinkByHref(\Drupal::url('view.test_click_sort.page_1', [], ['query' => ['order' => 'id', 'sort' => 'desc']]));
......
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