function menu_ui_form_node_type_form_validate

menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_state)

Submit handler for forms with menu options.

See also

menu_ui_form_node_type_form_alter()

File

core/modules/menu_ui/menu_ui.module, line 442
Allows administrators to customize the site's navigation menus.

Code

function menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_state) {
  $available_menus = array_filter($form_state->getValue('menu_options'));
  // If there is at least one menu allowed, the selected item should be in
  // one of them.
  if (count($available_menus)) {
    $menu_item_id_parts = explode(':', $form_state->getValue('menu_parent'));
    if (!in_array($menu_item_id_parts[0], $available_menus)) {
      $form_state->setErrorByName('menu_parent', t('The selected menu item is not under one of the selected menus.'));
    }
  }
  else {
    $form_state->setValue('menu_parent', '');
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!menu_ui!menu_ui.module/function/menu_ui_form_node_type_form_validate/8.1.x