Only show selected menu on menu_edit_item form.

Created on 12 April 2012, over 12 years ago
Updated 26 February 2023, almost 2 years ago

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.

๐Ÿ› Bug report
Status

Needs work

Version

10.1 โœจ

Component
Menu moduleย  โ†’

Last updated 2 months ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium jurgenr

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024