function menu_ui_form_node_type_form_validate

Same name in other branches
  1. 8.9.x core/modules/menu_ui/menu_ui.module \menu_ui_form_node_type_form_validate()
  2. 10 core/modules/menu_ui/menu_ui.module \menu_ui_form_node_type_form_validate()
  3. 11.x core/modules/menu_ui/menu_ui.module \menu_ui_form_node_type_form_validate()

Validate handler for forms with menu options.

See also

menu_ui_form_node_type_form_alter()

1 string reference to 'menu_ui_form_node_type_form_validate'
menu_ui_form_node_type_form_alter in core/modules/menu_ui/menu_ui.module
Implements hook_form_FORM_ID_alter() for \Drupal\node\NodeTypeForm.

File

core/modules/menu_ui/menu_ui.module, line 401

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 link is not under one of the selected menus.'));
        }
    }
    else {
        $form_state->setValue('menu_parent', '');
    }
}

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