Problem/Motivation

In version 2.13 of Menu Item extras, there were 3 additional theme suggestions offered for any menu:

  • menu__extras
  • menu__extras__[menu_name]
  • menu__extras__[menu_name]__[region]

In version 2.14, the menu__extras__[menu_name]__[region] suggestion is no longer being offered for Menu Block users, which breaks sites that relied on that theme suggestion. Looking at the menu block code, it seems to be because it's changing the menu theme to "menu", the same way this module does, to handle precedence:

Line 340, /src/plugin/Block/MenuBlock.php

   if (!empty($build['#theme'])) {
      // Add the configuration for use in menu_block_theme_suggestions_menu().
      $build['#menu_block_configuration'] = $this->configuration;
      // Set the generated label into the configuration array so it is
      // propagated to the theme preprocessor and template(s) as needed.
      $build['#menu_block_configuration']['label'] = $label;
      // Remove the menu name-based suggestion so we can control its precedence
      // better in menu_block_theme_suggestions_menu().
      $build['#theme'] = 'menu';
    }

With the additional checks in menu_item_extras_preprocess_block introduced in #3176154: menu_item_extras_preprocess_block() should be more specific and #3020650: User error on rendering second level menu items with Layout Builder Menu Blocks no longer get the data-region attribute added, which prevents that suggestion from showing.

Proposed resolution

If I understand the updates for the two issues below, it seems like the same logic could be achieved without breaking Menu Blocks by changing

&& strpos($variables['content']['#theme'], 'menu__') === 0

to

&& (strpos($variables['content']['#theme'], 'menu__') === 0 || $variables['content']['#theme'] === 'menu')

and removing the additional if ($variables['content']['#theme'] == $menu_theme) { check since, as far as I can tell, that was added before issue #3176154: menu_item_extras_preprocess_block() should be more specific was committed and seems to be redundant now. This is what the attached patch does.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jacobbell84 created an issue. See original summary.

ozin made their first commit to this issue’s fork.

  • ozin committed 17ff2d5 on 8.x-2.x authored by jacobbell84
    Issue #3210762 by jacobbell84, ozin: Version 2.14 breaks support for...
ozin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.