You are here

public function Page::validateOptionsForm in Drupal 9

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

Validate the options form.

Overrides PathPluginBase::validateOptionsForm

File

core/modules/views/src/Plugin/views/display/Page.php, line 458

Class

Page
The plugin that handles a full page.

Namespace

Drupal\views\Plugin\views\display

Code

public function validateOptionsForm(&$form, FormStateInterface $form_state) {
  parent::validateOptionsForm($form, $form_state);
  if ($form_state
    ->get('section') == 'menu') {
    $path = $this
      ->getOption('path');
    $menu_type = $form_state
      ->getValue([
      'menu',
      'type',
    ]);
    if ($menu_type == 'normal' && strpos($path, '%') !== FALSE) {
      $form_state
        ->setError($form['menu']['type'], $this
        ->t('Views cannot create normal menu links for paths with a % in them.'));
    }
    if ($menu_type == 'default tab' || $menu_type == 'tab') {
      $bits = explode('/', $path);
      $last = array_pop($bits);
      if ($last == '%') {
        $form_state
          ->setError($form['menu']['type'], $this
          ->t('A display whose path ends with a % cannot be a tab.'));
      }
    }
    if ($menu_type != 'none' && $form_state
      ->isValueEmpty([
      'menu',
      'title',
    ])) {
      $form_state
        ->setError($form['menu']['title'], $this
        ->t('Title is required for this menu type.'));
    }
  }
}