function Page::validateOptionsForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/display/Page.php \Drupal\views\Plugin\views\display\Page::validateOptionsForm()
  2. 8.9.x core/modules/views/src/Plugin/views/display/Page.php \Drupal\views\Plugin\views\display\Page::validateOptionsForm()
  3. 10 core/modules/views/src/Plugin/views/display/Page.php \Drupal\views\Plugin\views\display\Page::validateOptionsForm()

Overrides PathPluginBase::validateOptionsForm

File

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

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' && str_contains($path, '%')) {
            $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.'));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.