You are here

public function DisplayPluginBase::validateOptionsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm()

Validate the options form.

Overrides PluginBase::validateOptionsForm

2 calls to 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.
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 1864
Contains \Drupal\views\Plugin\views\display\DisplayPluginBase.

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 name must be letters, numbers, or underscores only.'));
        }
        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 (strpos($section, '_options') !== FALSE) {
    $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);
  }
}