Block menu field configuration like Viewmode get lost when a different than the default template is used

Created on 27 February 2025, 3 months ago

Problem/Motivation

When a different template than `menu--field-content.html.twig` like a more menu name specific kind like `menu--field-content--menu-name.html.twig` is used, the block configuration like the used viewmode is lost.

Steps to reproduce

  • Create an specific template based on the `menu--field-content.html.twig` using the name of the menu like `menu--field-content--menu-name.html.twig`
  • Check the menu items use always the _default_ viewmode even the block menu item is set as otherwise.
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain pakmanlh Barcelona

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @pakmanlh
  • First commit to issue fork.
  • 🇪🇸Spain rodrigoaguilera Barcelona

    I was able to reproduce and opened a MR to provide a workaround.

    It gets rid of the "base_hook" in the theme definition since according to the docs it is only used for suggestions.
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

    This allowed to have suggestions but a when #theme like "menu__field_content__MENU_NAME" was provided and template existed for it Drupal core treats it as a "menu" theme definition and it won't detect the variables for the "menu__field_content" theme definition.

    This basically demonstrates how weak was the decision to use a hook definition with double underscores, that confuses the Drupal theme system since is treated as a suggestion of "menu".

    Please review the change and confirm it can be a valid solution/workaround.

    I will start thinking about a 2.0 version of the module that gets rid of this ugly hack.

Production build 0.71.5 2024