Menu UI searches links by incorrect uri

Created on 9 February 2016, over 9 years ago
Updated 21 June 2023, about 2 years ago

Problem/Motivation

"menu_ui_get_menu_link_defaults()" doesn't consider the default menu in parent menu when we have two menu link items pointing to same node.

Steps to reproduce

Add a new menu
Add the new menu to the Article content type.
Add a new article
Add a menu link into the new menu
Add a menu link into the main navigation.
Go to the edit form for the article. The main menu link should be the default, but the menu link from the new menu is.

Steps taken from #21

Proposed resolution

Use valid URI entity:node/ in the query

Remaining tasks

Needs review from committer.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Original report by AndreyMaximov

There is incorrect query in function menu_ui_get_menu_link_defaults() that never returns results.

function menu_ui_get_menu_link_defaults(NodeInterface $node) {
  //...
  // Give priority to the default menu
  $type_menus = $node_type->getThirdPartySetting('menu_ui', 'available_menus', array('main'));
  if (in_array($menu_name, $type_menus)) {
    $query = \Drupal::entityQuery('menu_link_content')
      ->condition('link.uri', 'node/' . $node->id())
      ->condition('menu_name', $menu_name)
      ->sort('id', 'ASC')
      ->range(0, 1);
    $result = $query->execute();

entity: scheme is missed.
The fix is pretty simple:

  ->condition('link.uri', 'node/' . $node->id())

should become

  ->condition('link.uri', 'entity:node/' . $node->id())

The bug results in extra query executed when a node edit page is opened.

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
Menu UI 

Last updated 4 days ago

No maintainer
Created by

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