Skip to content
Snippets Groups Projects
Commit a05ca5d2 authored by catch's avatar catch
Browse files

Issue #2653346 by Wim Leers, borisson_: Add UncacheableDependencyTrait: the...

Issue #2653346 by Wim Leers, borisson_: Add UncacheableDependencyTrait: the opposite of UnchangingCacheableDependencyTrait
parent e60bb570
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Contains \Drupal\Core\Cache\UncacheableDependencyTrait.
*/
namespace Drupal\Core\Cache;
/**
* Trait to implement CacheableDependencyInterface for uncacheable objects.
*
* Use this for objects that are never cacheable.
*
* @see \Drupal\Core\Cache\CacheableDependencyInterface
*/
trait UncacheableDependencyTrait {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return 0;
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\history\Plugin\views\filter;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
......@@ -17,6 +18,8 @@
*/
class HistoryUserTimestamp extends FilterPluginBase {
use UncacheableDependencyTrait;
// Don't display empty space where the operator would be.
var $no_operator = TRUE;
......@@ -93,12 +96,4 @@ public function adminSummary() {
}
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// This filter depends on the current time and therefore is never cacheable.
return 0;
}
}
......@@ -3,28 +3,10 @@
namespace Drupal\early_rendering_controller_test;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;
class CacheableTestDomainObject extends TestDomainObject implements CacheableDependencyInterface {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return 0;
}
use UncacheableDependencyTrait;
}
......@@ -3,6 +3,7 @@
namespace Drupal\views\Plugin\views\sort;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -12,6 +13,8 @@
*/
class Random extends SortPluginBase implements CacheableDependencyInterface {
use UncacheableDependencyTrait;
/**
* {@inheritdoc}
*/
......@@ -28,25 +31,4 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['order']['#access'] = FALSE;
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return 0;
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return [];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment