Commit 0f3327fe authored by catch's avatar catch

Issue #2316459 by Gábor Hojtsy: Fixed Menu ui module refers to nonexistent...

Issue #2316459 by Gábor Hojtsy: Fixed Menu ui module refers to nonexistent library, lacks menu parent validation on content type settings.
parent f3b3f268
......@@ -459,7 +459,7 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat
'#type' => 'details',
'#title' => t('Menu settings'),
'#attached' => array(
'library' => array('menu/drupal.menu.admin'),
'library' => array('menu_ui/drupal.menu_ui.admin'),
),
'#group' => 'additional_settings',
);
......@@ -485,9 +485,30 @@ function menu_ui_form_node_type_form_alter(&$form, FormStateInterface $form_stat
'#attributes' => array('class' => array('menu-title-select')),
);
$form['actions']['submit']['#validate'][] = 'menu_ui_form_node_type_form_validate';
$form['actions']['submit']['#submit'][] = 'menu_ui_form_node_type_form_submit';
}
/**
* Submit handler for forms with menu options.
*
* @see menu_ui_form_node_type_form_alter().
*/
function menu_ui_form_node_type_form_validate(&$form, FormStateInterface $form_state) {
$available_menus = array_filter($form_state['values']['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['values']['menu_parent']);
if (!in_array($menu_item_id_parts[0], $available_menus)) {
form_set_error('menu_parent', $form_state, t('The selected menu item is not under one of the selected menus.'));
}
}
else {
$form_state['values']['menu_parent'] = '';
}
}
/**
* Submit handler for forms with menu options.
*
......
......@@ -61,6 +61,16 @@ function testMenuNodeFormWidget() {
$node = $this->drupalGetNodeByTitle($node_title);
$this->assertEqual($node->getTitle(), $edit['title[0][value]']);
// Test that we cannot set a menu item from a menu that is not set as
// available.
$edit = array(
'menu_options[tools]' => 1,
'menu_parent' => 'main:',
);
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertText(t('The selected menu item is not under one of the selected menus.'));
$this->assertNoRaw(t('The content type %name has been updated.', array('%name' => 'Basic page')));
// Enable Tools menu as available menu.
$edit = array(
'menu_options[main]' => 1,
......@@ -68,6 +78,7 @@ function testMenuNodeFormWidget() {
'menu_parent' => 'main:',
);
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertRaw(t('The content type %name has been updated.', array('%name' => 'Basic page')));
// Create a node.
$node_title = $this->randomMachineName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment