Menus are not rendered when machine name starting with hyphen

Created on 5 February 2020, over 5 years ago
Updated 16 August 2024, 9 months ago

Problem/Motivation

I named my custom menus starting with a * to distinguish them from the system menus e.g:

*Navigation Left
*Navigation Middle
*Navigation Right

The machine names are like that:

-navigation-left
-navigation-middle
-navigation-right

Menus are not rendered because the corresponding theme hook becomes like menu___name. The ThemeManager::render() searches for hook implementation by stripping double underscores. In this case it fails to find it because the hook name contains triple underscore.
https://git.drupalcode.org/project/drupal/blob/8.8.2/core/lib/Drupal/Cor...

Steps to reproduce

  • Create a new menu in /admin/structure/menu
  • title: *Left Navigation
  • Add a menu link to this menu (no matter to where this link is)
  • Create another new menu in /admin/structure/menu (to show the difference)
  • title: Right navigation
  • Add a menu link to this menu (no matter to where this link is)
  • Go to /admin/structure/block to place both menus in your main menu
  • Place the Primary Menu Block and select the first menu ( *Left Navigation ) and save it
  • Place the Primary Menu Block and select the second menu (Right Navigation) and save it
  • Now go to your homepage, you will notice that Right Navigation was created with the link, while *Left Navigation was not

Proposed resolution

Prevent menu names from starting with a leading -

Remaining tasks

Patch review

User interface changes

Before patch is applied:

After patch applied:

πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
Menu moduleΒ  β†’

Last updated 5 days ago

Created by

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

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.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    I tested this on 11.x, fresh standard install, today and was not able to reproduce the problem using the steps in the Issue Summary. Therefor closing as outdated.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β†’ (starting from "Install Drupal core").

    Thanks!

Production build 0.71.5 2024