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.

Issue fork drupal-1529380

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Version: 7.12 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

cedewey’s picture

Version: 7.x-dev » 10.1.x-dev
Category: Feature request » Bug report
Issue summary: View changes
FileSize
51.19 KB

I 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.

Screenshot of the form to add a menu item to a menu called Mega Menu. The parent menu item can be a menu item in a different menu, for example the Footer Menu.

enaznin made their first commit to this issue’s fork.

enaznin’s picture

Status: Active » Needs review
rajneeshb’s picture

FileSize
392.84 KB
235.8 KB

Reviewed MR!3511 Looks good. Attaching screenshots for the same.

Rashmisoni made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests, +Needs issue summary update

Seems 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

VladimirAus made their first commit to this issue’s fork.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.