Skip to content
Snippets Groups Projects

[#3521212] Fix CS/SA/eslint/cspell issues.

Files
10
@@ -4,15 +4,16 @@ namespace Drupal\views_advanced_cache\Plugin\views\cache;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\views\Views;
use Drupal\Core\Url;
use Drupal\Core\Utility\Token;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ResultRow;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -51,16 +52,51 @@ class AdvancedViewsCache extends CachePluginBase {
*/
protected $time;
protected $lifespans = [60, 300, 900, 1800, 3600, 21600, 43200, 86400, 604800];
/**
* Token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* Seconds used to build select field options for cache lifetime.
*
* @var array
*/
protected $lifespans = [
60,
300,
900,
1800,
3600,
21600,
43200,
86400,
604800,
];
/**
* Select field options array built from lifespans.
*
* @var array
*/
public $lifespanOptions = [];
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter, TimeInterface $datetime_time) {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
DateFormatterInterface $date_formatter,
TimeInterface $datetime_time,
Token $token,
) {
$this->dateFormatter = $date_formatter;
$this->time = $datetime_time;
$this->token = $token;
parent::__construct($configuration, $plugin_id, $plugin_definition);
@@ -77,7 +113,8 @@ class AdvancedViewsCache extends CachePluginBase {
$plugin_id,
$plugin_definition,
$container->get('date.formatter'),
$container->get('datetime.time')
$container->get('datetime.time'),
$container->get('token')
);
}
@@ -85,21 +122,21 @@ class AdvancedViewsCache extends CachePluginBase {
* {@inheritdoc}
*/
public function summaryTitle() {
// Display a summary of: cache tags,
// Display a summary of: cache tags.
$num_cache_tags = count(array_merge($this->options['cache_tags'], $this->options['cache_tags_exclude']) ?: []);
$cache_tags = '';
if ($num_cache_tags > 0) {
$cache_tags = "$num_cache_tags tags";
}
// cache contexts,
// Cache contexts.
$num_cache_contexts = count(array_merge($this->options['cache_contexts'], $this->options['cache_contexts_exclude']) ?: []);
$cache_contexts = '';
if ($num_cache_contexts > 0) {
$cache_contexts = "$num_cache_contexts contexts";
}
// and max-age.
// And max-age.
$results_lifespan = $this->getLifespan('results');
$output_lifespan = $this->getLifespan('output');
$lifetime = '';
@@ -146,7 +183,7 @@ class AdvancedViewsCache extends CachePluginBase {
*
* By prefixing the tag with a "-" it will
* be removed from the cache metadata. Removing cache tags should be
* used sparingly but may be useful to resolve issues uneccessary cache tags
* used sparingly but may be useful to resolve issues unnecessary cache tags
* added by other modules
* (ex. https://www.drupal.org/project/drupal/issues/2352175).
*
@@ -154,7 +191,12 @@ class AdvancedViewsCache extends CachePluginBase {
*/
public function buildCacheTagOptions(array &$form, FormStateInterface $form_state) {
$cache_tags_docs = Link::fromTextAndUrl('documentation', Url::fromUri('https://www.drupal.org/docs/8/api/cache-api/cache-tags'))->toString();
$cache_tags_exclude = array_map(function ($c) { return "- $c"; }, $this->options['cache_tags_exclude']);
$cache_tags_exclude = array_map(
function ($c) {
return "- $c";
},
$this->options['cache_tags_exclude']
);
// Filter out some of the default cache tags we don't care about.
// This should mostly be the entity_type list cache tags ex. node_list.
$default_cache_tags = array_diff(parent::getCacheTags(), ['extensions', 'config:views.view.' . $this->view->id()]);
@@ -177,7 +219,7 @@ class AdvancedViewsCache extends CachePluginBase {
'#default_value' => implode("\n", array_merge($cache_tags, $cache_tags_exclude)),
];
$optgroup_arguments = (string) t('Arguments');
$optgroup_arguments = (string) $this->t('Arguments');
$options = [];
// $globalTokens = $this->getAvailableGlobalTokens(FALSE, ['current-user']);
@@ -231,11 +273,19 @@ class AdvancedViewsCache extends CachePluginBase {
'#open' => TRUE,
];
$cache_contexts_exclude = array_map(function ($c) { return "- $c"; }, $this->options['cache_contexts_exclude']);
$cache_contexts_exclude = array_map(
function ($c) {
return "- $c";
},
$this->options['cache_contexts_exclude']
);
$form['cache_contexts']['cache_contexts'] = [
'#type' => 'textarea',
'#title' => $this->t('Cache Contexts'),
'#default_value' => implode("\n", array_merge($this->options['cache_contexts'], $cache_contexts_exclude)) ,
'#default_value' => implode("\n", array_merge(
$this->options['cache_contexts'],
$cache_contexts_exclude
)),
'#description' => $this->t('List cache contexts (separated by new lines).'),
];
}
@@ -302,7 +352,7 @@ class AdvancedViewsCache extends CachePluginBase {
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$lifespan = [];
$cache_lifespan = $form_state->getValue(['cache_options', 'cache_lifespan']);
// Validate lifespan format
// Validate lifespan format.
foreach (['output_lifespan', 'results_lifespan'] as $field) {
$custom = $cache_lifespan[$field] == 'custom';
if ($custom && !is_numeric($cache_lifespan[$field . '_custom'])) {
@@ -387,7 +437,7 @@ class AdvancedViewsCache extends CachePluginBase {
$default_cache_tags = parent::getCacheTags();
$cache_tags = array_map(function ($tag) {
$value = $this->view->getStyle()->tokenizeValue($tag, 0);
return \Drupal::token()->replace($value);
return $this->token->replace($value);
}, $cache_tags);
$cache_tags = Cache::mergeTags($cache_tags, $default_cache_tags);
}
Loading