"Parent link" option unusable in group_content_menu menus

Created on 27 May 2022, over 2 years ago
Updated 25 May 2023, over 1 year ago

Problem/Motivation

When this module and the contrib module group_content_menu β†’ are both used, the options list in "Parent link" for group_content_menu menus are empty.

I was able to track this down to menu_item_extras_form_menu_link_content_form_alter() in https://git.drupalcode.org/project/menu_item_extras/-/blame/8.x-2.x/menu....

Steps to reproduce

This can be reproduced on https://simplytest.me/ by installing the latest version of both menu_item_extras and group_content_menu. Then configure your site as below:

  1. Go to /admin/modules and enable "Group Node"
  2. Go to /admin/group/types/add and create a test group type
    • Check the box "Automatically configure an administrative role"
    • Check the box "Automatically assign this administrative role to group creators"
  3. Go to /admin/structure/group_content_menu_types and create two menu types
    • first menu type called "Left navigation"
    • second menu type called "Utilities navigation"
  4. Go to /admin/group/types and click the dropdown button in the row of your group type and click "Set available content"
  5. Click "Install" for both group menu types
    • Check the box labeled "Automatically create a menu when a group is created"
    • Check the box labeled "Automatically create a "Home" link for the menu"
  6. Go to /admin/group and create a group
  7. Go to the admin page of your newly-created group (for example, /group/1)
  8. Click the "Group Menus" tab
  9. Click "Edit" on one of your group menus
  10. Click the "Add link" button
  11. Expected result: See options in the "Parent link" field. Actual result: No options available because they are being unset.

Changing https://git.drupalcode.org/project/menu_item_extras/-/blame/8.x-2.x/menu... $bundle = $entity->bundle(); back to $entity->get('menu_name')->getString(); does ensure "Parent link" options are present for group_menu_content menus (see below screenshot), but I realize that the decision was to go with $bundle = $entity->bundle(); because of https://www.drupal.org/project/menu_item_extras/issues/3062981 β†’ .

Proposed resolution

Not sure the best solution. Maybe something like the following (haven't tested it yet):

$entity = $form_object->getEntity();
$bundle = $entity->bundle();
foreach ($form['menu_parent']['#options'] as $option_id => $option) {
  if (str_starts_with($option_id, 'group_menu_link_content')) {
    // If we're adding a link to a group_content_menu, get the
    // menu name from the entity instead so that we do not
    // unset the "Parent link" options we should have.
    $bundle = $entity->get('menu_name')->getString();
  }
  if (strpos($option_id, $bundle) !== 0) {
       unset($form['menu_parent']['#options'][$option_id]);
  }
}

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Menu item form

Created by

πŸ‡ΊπŸ‡ΈUnited States cainaru Norwood, NY, USA

Live updates comments and jobs are added and updated live.
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