function Date::valueForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::valueForm()
  2. 8.9.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::valueForm()
  3. 11.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::valueForm()

Add a type selector to the value form.

Overrides NumericFilter::valueForm

File

core/modules/views/src/Plugin/views/filter/Date.php, line 28

Class

Date
Filter to handle dates stored as a timestamp.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
    if (!$form_state->get('exposed')) {
        $form['value']['type'] = [
            '#type' => 'radios',
            '#title' => $this->t('Value type'),
            '#options' => [
                'date' => $this->t('A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.'),
                'offset' => $this->t('An offset from the current time such as "@example1" or "@example2"', [
                    '@example1' => '+1 day',
                    '@example2' => '-2 hours -30 minutes',
                ]),
            ],
            '#default_value' => !empty($this->value['type']) ? $this->value['type'] : 'date',
        ];
    }
    parent::valueForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.