When adding or editing a menu link starting form the menu_overview_form we go to the menu_edit_item form.
It's confusing and sometimes hard to explain why the Parent link dropdown shows all available menus when starting from a selected menu.
Wouldn't it be better to only show the selected menu?
There's an original_item array containing the selected menu name this could be used to alter the options array.
What's the reason to show all menus, because it could easily be done altering the $form['parent']['#options'] array.
/**
*
* Implements hook_form_BASE_FORM_ID_alter().
*/
function duo_menu_form_menu_edit_item_alter(&$form, $form_state) {
// Alter parent menu options in order to only show the selected menu
// Menu has to be in an array because we want to use menu_parent_options function
// The form array always has a original_item variable from which we can get the selected form name
$duo_menus = array($form['original_item']['#value']['menu_name'] => $form['original_item']['#value']['menu_name']);
// Generate a list of possible parents (not including this link or descendants).
$duo_menu_options = menu_parent_options($duo_menus, 0);
$form['parent']['#options'] = $duo_menu_options;
}
Jurgen.
Comments
Comment #2
cedeweyI just noticed this is Drupal's default behavior on a Drupal 9.4 site. This would be a great improvement, especially in situations where there are multiple menus with numerous menu items in which the same page is included in more than one menu.
I'm updating this to be a 10.x issue.
Also, I consider this a bug. If I am managing a specific menu, I shouldn't be able to add it to a different menu.
Comment #5
enaznin commentedComment #6
rajneeshb commentedReviewed MR!3511 Looks good. Attaching screenshots for the same.
Comment #8
smustgrave commentedSeems to be some failures in the MR.
Also as a bug this will require a test case.
issue summary should also be updated to reflect the proposed solution
Thanks