function DisplayPluginBase::validateOptionsForm
Same name in other branches
- 9 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm()
- 8.9.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm()
- 11.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm()
Overrides PluginBase::validateOptionsForm
2 methods override DisplayPluginBase::validateOptionsForm()
- DisplayTest::validateOptionsForm in core/
modules/ views/ tests/ modules/ views_test_data/ src/ Plugin/ views/ display/ DisplayTest.php - Validate the options form.
- PathPluginBase::validateOptionsForm in core/
modules/ views/ src/ Plugin/ views/ display/ PathPluginBase.php - Validate the options form.
File
-
core/
modules/ views/ src/ Plugin/ views/ display/ DisplayPluginBase.php, line 1885
Class
- DisplayPluginBase
- Base class for views display plugins.
Namespace
Drupal\views\Plugin\views\displayCode
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$section = $form_state->get('section');
switch ($section) {
case 'display_title':
if ($form_state->isValueEmpty('display_title')) {
$form_state->setError($form['display_title'], $this->t('Display title may not be empty.'));
}
break;
case 'css_class':
$css_class = $form_state->getValue('css_class');
if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) {
$form_state->setError($form['css_class'], $this->t('CSS classes must be alphanumeric or dashes only.'));
}
break;
case 'display_id':
if ($form_state->getValue('display_id')) {
if (preg_match('/[^a-z0-9_]/', $form_state->getValue('display_id'))) {
$form_state->setError($form['display_id'], $this->t('Display machine name must contain only lowercase letters, numbers, or underscores.'));
}
foreach ($this->view->displayHandlers as $id => $display) {
if ($id != $this->view->current_display && ($form_state->getValue('display_id') == $id || isset($display->new_id) && $form_state->getValue('display_id') == $display->new_id)) {
$form_state->setError($form['display_id'], $this->t('Display id should be unique.'));
}
}
}
break;
case 'query':
if ($this->view->query) {
$this->view->query
->validateOptionsForm($form['query'], $form_state);
}
break;
}
// Validate plugin options. Every section with "_options" in it, belongs to
// a plugin type, like "style_options".
if (str_contains($section, '_options')) {
$plugin_type = str_replace('_options', '', $section);
// Load the plugin and let it handle the validation.
if ($plugin = $this->getPlugin($plugin_type)) {
$plugin->validateOptionsForm($form[$section], $form_state);
}
}
foreach ($this->extenders as $extender) {
$extender->validateOptionsForm($form, $form_state);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.