You are here

public function DisplayPluginBase::validateOptionsForm in Views (for Drupal 7) 8.3

Validate the options form.

Overrides PluginBase::validateOptionsForm

2 calls to DisplayPluginBase::validateOptionsForm()
DisplayTest::validateOptionsForm in tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm().
Page::validateOptionsForm in lib/Drupal/views/Plugin/views/display/Page.php
Validate the options form.
2 methods override DisplayPluginBase::validateOptionsForm()
DisplayTest::validateOptionsForm in tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm().
Page::validateOptionsForm in lib/Drupal/views/Plugin/views/display/Page.php
Validate the options form.

File

lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php, line 2054
Definition of Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Namespace

Drupal\views\Plugin\views\display

Code

public function validateOptionsForm(&$form, &$form_state) {
  switch ($form_state['section']) {
    case 'display_title':
      if (empty($form_state['values']['display_title'])) {
        form_error($form['display_title'], t('Display title may not be empty.'));
      }
      break;
    case 'css_class':
      $css_class = $form_state['values']['css_class'];
      if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) {
        form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.'));
      }
      break;
    case 'display_id':
      if ($form_state['values']['display_id']) {
        if (preg_match('/[^a-z0-9_]/', $form_state['values']['display_id'])) {
          form_error($form['display_id'], t('Display name must be letters, numbers, or underscores only.'));
        }
        foreach ($this->view->display as $id => $display) {
          if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || isset($display->new_id) && $form_state['values']['display_id'] == $display->new_id)) {
            form_error($form['display_id'], t('Display id should be unique.'));
          }
        }
      }
      break;
    case 'style_options':
      $style = TRUE;
    case 'row_options':

      // if row, $style will be empty.
      $plugin = $this
        ->getPlugin(empty($style) ? 'row' : 'style');
      if ($plugin) {
        $plugin
          ->validateOptionsForm($form[$form_state['section']], $form_state);
      }
      break;
    case 'access_options':
      $plugin = $this
        ->getPlugin('access');
      if ($plugin) {
        $plugin
          ->validateOptionsForm($form['access_options'], $form_state);
      }
      break;
    case 'query':
      if ($this->view->query) {
        $this->view->query
          ->validateOptionsForm($form['query'], $form_state);
      }
      break;
    case 'cache_options':
      $plugin = $this
        ->getPlugin('cache');
      if ($plugin) {
        $plugin
          ->validateOptionsForm($form['cache_options'], $form_state);
      }
      break;
    case 'exposed_form_options':
      $plugin = $this
        ->getPlugin('exposed_form');
      if ($plugin) {
        $plugin
          ->validateOptionsForm($form['exposed_form_options'], $form_state);
      }
      break;
    case 'pager_options':
      $plugin = $this
        ->getPlugin('pager');
      if ($plugin) {
        $plugin
          ->validateOptionsForm($form['pager_options'], $form_state);
      }
      break;
  }
  foreach ($this->extender as $extender) {
    $extender
      ->validateOptionsForm($form, $form_state);
  }
}