I have a menu that want to behave differently based on the region its displayed in.
By default there is no file suggestion that differentiates which twig file to be used for a menu based on the region. Even if there was I think for the purpose of adding/removing a class it is more convinient to modify a variable in a preprocess function than keeping to versions of a twig template.
here is what I have
function THEMENAME_preprocess_menu(&$vars) {
$test = "";
if ($vars['menu_name'] == 'main') {
if (!isset($vars['attributes']['class'])) {
$vars['attributes']['class'] = [];
}
//test region or block name before merging
$vars['attributes']['class'] = array_merge($vars['attributes']['class'], ['main-menu-regionA']);
}
}
I need a way to test the region or the block name to add a specific class to the parent UL element
my 2nd choice would be to explore the hook_theme_suggestions_alter