function Block::blockValidate
File
-
modules/
ctools_views/ src/ Plugin/ Display/ Block.php, line 414
Class
- Block
- Provides a Block display plugin.
Namespace
Drupal\ctools_views\Plugin\DisplayCode
public function blockValidate(ViewsBlock $block, array $form, FormStateInterface $form_state) {
// Checkout validateOptionsForm on filters before saving this.
if ($form_state->hasValue('exposed')) {
$handlers = $this->view
->getDisplay()
->getHandlers('filter');
$values = $form_state->getValue('exposed');
foreach ($handlers as $key => $handler) {
if ($handler->isExposed()) {
$identifier = $handler->options['expose']['identifier'];
$handler_form_state = new FormState();
$handler_form_state->setValues($values);
$handler->validateExposed($form, $handler_form_state);
/*
* Select list doesn't change validated_exposed_input value
* when "All" is selected.
*/
// @todo Determine whether this is actually necessary or not.
if (isset($handler->options['type']) && $handler->options['type'] === 'select') {
if ($values['filter-' . $key][$identifier] === 'All') {
$handler->validated_exposed_input = NULL;
}
}
foreach ($handler_form_state->getErrors() as $name => $message) {
$form_state->setErrorByName($name, $message);
}
// Overwrite the value with its validated counterpart, if one exists.
if (property_exists($handler, 'validated_exposed_input')) {
$form_state->setValue([
'exposed',
$key,
], [
$identifier => $handler->validated_exposed_input,
]);
}
}
}
}
}