Skip to content
Snippets Groups Projects

Added changes from patch #43.

3 files
+ 98
5
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -22,6 +22,11 @@
)]
class Time extends CachePluginBase {
/**
* Time-based lifespan custom.
*/
const LIFESPAN_CUSTOM = -1;
/**
* {@inheritdoc}
*/
@@ -86,7 +91,8 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$options = [60, 300, 1800, 3600, 21600, 518400];
$options = array_map([$this->dateFormatter, 'formatInterval'], array_combine($options, $options));
$options = [0 => $this->t('Never cache')] + $options + ['custom' => $this->t('Custom')];
// Use LIFESPAN_CUSTOM for custom timed-based since configuration expects an integer.
$options = [0 => $this->t('Never cache')] + $options + [static::LIFESPAN_CUSTOM => $this->t('Custom')];
$form['results_lifespan'] = [
'#type' => 'select',
@@ -104,7 +110,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
'#default_value' => $this->options['results_lifespan_custom'],
'#states' => [
'visible' => [
':input[name="cache_options[results_lifespan]"]' => ['value' => 'custom'],
':input[name="cache_options[results_lifespan]"]' => ['value' => static::LIFESPAN_CUSTOM],
],
],
];
@@ -124,7 +130,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
'#default_value' => $this->options['output_lifespan_custom'],
'#states' => [
'visible' => [
':input[name="cache_options[output_lifespan]"]' => ['value' => 'custom'],
':input[name="cache_options[output_lifespan]"]' => ['value' => static::LIFESPAN_CUSTOM],
],
],
];
@@ -137,7 +143,7 @@ public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$custom_fields = ['output_lifespan', 'results_lifespan'];
foreach ($custom_fields as $field) {
$cache_options = $form_state->getValue('cache_options');
if ($cache_options[$field] == 'custom' && !is_numeric($cache_options[$field . '_custom'])) {
if ($cache_options[$field] == static::LIFESPAN_CUSTOM && !is_numeric($cache_options[$field . '_custom'])) {
$form_state->setError($form[$field . '_custom'], $this->t('Custom time values must be numeric.'));
}
}
@@ -156,7 +162,7 @@ public function summaryTitle() {
* Gets the value for the lifespan of the given type.
*/
protected function getLifespan($type) {
$lifespan = $this->options[$type . '_lifespan'] == 'custom' ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
$lifespan = $this->options[$type . '_lifespan'] == static::LIFESPAN_CUSTOM ? $this->options[$type . '_lifespan_custom'] : $this->options[$type . '_lifespan'];
return $lifespan;
}
Loading