What you get in $hook
doesn't say for which menu the preprocess function is called. It's simple a suggestion Drupal is picking up in ThemeManager::render()
.
// Invoke hook_theme_suggestions_HOOK().
$suggestions = $this->moduleHandler->invokeAll('theme_suggestions_' . $base_theme_hook, [
$variables,
]);
// If the theme implementation was invoked with a direct theme suggestion
// like '#theme' => 'node__article', add it to the suggestions array before
// invoking suggestion alter hooks.
if (isset($info['base hook'])) {
$suggestions[] = $hook;
}
// Invoke hook_theme_suggestions_alter() and
// hook_theme_suggestions_HOOK_alter().
$hooks = [
'theme_suggestions',
'theme_suggestions_' . $base_theme_hook,
];
$this->moduleHandler->alter($hooks, $suggestions, $variables, $base_theme_hook);
$this->alter($hooks, $suggestions, $variables, $base_theme_hook);
// Check if each suggestion exists in the theme registry, and if so,
// use it instead of the base hook. For example, a function may use
// '#theme' => 'node', but a module can add 'node__article' as a suggestion
// via hook_theme_suggestions_HOOK_alter(), enabling a theme to have
// an alternate template file for article nodes.
foreach (array_reverse($suggestions) as $suggestion) {
if ($theme_registry->has($suggestion)) {
$info = $theme_registry->get($suggestion);
break;
}
}
olivero_theme_suggestions_menu_alter()
is one of the hooks that alter the suggestions for the menu template file. There could be a module doing a similar suggestion, in your case.
function olivero_theme_suggestions_menu_alter(&$suggestions, array $variables) {
if (isset($variables['attributes']['region'])) {
$suggestions[] = 'menu__' . $variables['attributes']['region'];
}
}
What you are looking for is the menu machine name, stored in $variables['menu_name']
as documented in menu.html.twig.
If the purpose is hiding a menu item, using that preprocess hook is not the solution. To hide a menu item is sufficient, for example, to avoid the currently logged-in user has access to the route used for that menu item. In that case, Drupal won't show the menu item.