function Date::validateExposed
Same name in this branch
- 11.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::validateExposed()
Same name and namespace in other branches
- 9 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::validateExposed()
- 8.9.x core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::validateExposed()
- 10 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date::validateExposed()
Overrides Date::validateExposed
File
-
core/
modules/ datetime/ src/ Plugin/ views/ filter/ Date.php, line 106
Class
- Date
- Date/time views filter.
Namespace
Drupal\datetime\Plugin\views\filterCode
public function validateExposed(&$form, FormStateInterface $form_state) : void {
// Do not validate value if filter is not exposed or grouped.
if (empty($this->options['exposed']) || $this->options['is_grouped']) {
return;
}
$identifier = $this->options['expose']['identifier'];
$input = $form_state->getValue($identifier);
$values = [];
if (is_array($input)) {
if (!empty($input['value'])) {
$values[] = $input['value'];
}
else {
if (!empty($input['min'])) {
$values[] = $input['min'];
}
if (!empty($input['max'])) {
$values[] = $input['max'];
}
}
}
elseif (!empty($input)) {
$values[] = $input;
}
foreach ($values as $value) {
try {
(new DrupalDateTime($value))->getTimestamp();
} catch (\Throwable) {
if (isset($form[$identifier])) {
$field =& $form[$identifier];
}
elseif (isset($form[$identifier . '_wrapper'])) {
$field =& $form[$identifier . '_wrapper'];
}
if (isset($field)) {
// Set the form error message.
$form_state->setError($field, $this->t('Invalid date format.'));
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.