function Date::validateValidTime

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

Validate that the time values convert to something usable.

2 calls to Date::validateValidTime()
Date::validateExposed in core/modules/views/src/Plugin/views/filter/Date.php
Validate the exposed handler form.
Date::validateOptionsForm in core/modules/views/src/Plugin/views/filter/Date.php
Simple validate handler.

File

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

Class

Date
Filter to handle dates stored as a timestamp.

Namespace

Drupal\views\Plugin\views\filter

Code

public function validateValidTime(&$form, FormStateInterface $form_state, $operator, $value) {
    $operators = $this->operators();
    if ($operators[$operator]['values'] == 1) {
        $convert = strtotime($value['value']);
        if (!empty($form['value']) && ($convert == -1 || $convert === FALSE)) {
            $form_state->setError($form['value'], $this->t('Invalid date format.'));
        }
    }
    elseif ($operators[$operator]['values'] == 2) {
        $min = strtotime($value['min']);
        if ($min == -1 || $min === FALSE) {
            $form_state->setError($form['min'], $this->t('Invalid date format.'));
        }
        $max = strtotime($value['max']);
        if ($max == -1 || $max === FALSE) {
            $form_state->setError($form['max'], $this->t('Invalid date format.'));
        }
    }
}

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