Can't set attribute in Menu that has sub menus.

Created on 22 June 2023, over 1 year ago

Problem/Motivation

I'm having issue on setting attributes if the menu has sub menu
Ex.

function hook_preprocess_menu(&$variables) {
$items = &$variables['items'];
 foreach ($items as $key => &$item) {
  if ($item is Child Menu A) {
    $item['attributes']->setAttribute('class', ['custom-class']);
  }
 }
}

i would expect that menu should be <a href="/path/to/link" class="expanded level4 custom-class" >Child Menu A</a>
but it turns out <a href="/path/to/link" class="expanded level4" >Child Menu A</a>

Steps to reproduce

Create something like this & enable Show as expanded.
Main Menu A
-- Child Menu A
----Sub Menu A
----Sub Menu B
----Sub Menu C
Main Menu B

πŸ’¬ Support request
Status

Active

Version

10.0 ✨

Component
Menu systemΒ  β†’

Last updated about 21 hours ago

Created by

πŸ‡΅πŸ‡­Philippines _renify_ cebu

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

Comments & Activities

Production build 0.71.5 2024