Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DisplayPluginBase.php

function DisplayPluginBase::validateOptionsForm

Overrides PluginBase::validateOptionsForm

2 calls to DisplayPluginBase::validateOptionsForm()
PathPluginBase::validateOptionsForm in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Validate the options form.
PathPluginBase::validateOptionsForm in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Validate the options form.
1 method overrides DisplayPluginBase::validateOptionsForm()
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\display

Code

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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal