Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Time.php

function Time::buildOptionsForm

Overrides PluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/cache/Time.php, line 79

Class

Time
Simple caching of query results for Views displays.

Namespace

Drupal\views\Plugin\views\cache

Code

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'),
    ];
    $form['results_lifespan'] = [
        '#type' => 'select',
        '#title' => $this->t('Query results'),
        '#description' => $this->t('The length of time raw query results should be cached.'),
        '#options' => $options,
        '#default_value' => $this->options['results_lifespan'],
    ];
    $form['results_lifespan_custom'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Seconds'),
        '#size' => '25',
        '#maxlength' => '30',
        '#description' => $this->t('Length of time in seconds raw query results should be cached.'),
        '#default_value' => $this->options['results_lifespan_custom'],
        '#states' => [
            'visible' => [
                ':input[name="cache_options[results_lifespan]"]' => [
                    'value' => 'custom',
                ],
            ],
        ],
    ];
    $form['output_lifespan'] = [
        '#type' => 'select',
        '#title' => $this->t('Rendered output'),
        '#description' => $this->t('The length of time rendered HTML output should be cached.'),
        '#options' => $options,
        '#default_value' => $this->options['output_lifespan'],
    ];
    $form['output_lifespan_custom'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Seconds'),
        '#size' => '25',
        '#maxlength' => '30',
        '#description' => $this->t('Length of time in seconds rendered HTML output should be cached.'),
        '#default_value' => $this->options['output_lifespan_custom'],
        '#states' => [
            'visible' => [
                ':input[name="cache_options[output_lifespan]"]' => [
                    'value' => 'custom',
                ],
            ],
        ],
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal