Add hook to template file base on vocabulary

Created on 12 September 2017, over 7 years ago
Updated 19 September 2023, over 1 year ago

Hello,

For easy for user to override twig, I think you should add code for hook template file

HierarchicalTaxonomyMenuBlock.php, we add bold code to line 283

return [
'#theme' => 'hierarchical_taxonomy_menu',
'#menu_tree' => $tree,
'#route_tid' => $route_tid,
'#cache' => ['max-age' => 0],
'#current_depth' => 0,
'#vocabularies' => $vocabulary,
'#max_depth' => $max_depth,
'#attached' => [
'library' => [
'hierarchical_taxonomy_menu/hierarchical_taxonomy_menu',
],
'drupalSettings' => [
'collapsibleMenu' => $this->configuration['collapsible'],
],
],
];
}

hierarchical_taxonomy_menu.module, add bold line and hook

/**
* Implements hook_theme().
*/
function hierarchical_taxonomy_menu_theme($existing, $type, $theme, $path) {
return [
'hierarchical_taxonomy_menu' => [
'variables' => [
'menu_tree' => [],
'route_tid' => NULL,
'vocabularies' => NULL,
'current_depth' => 0,
'max_depth' => 0,
],
],
];
}

Add hook

/**
* Implements hook_theme_suggestions_HOOK().
*/
function hierarchical_taxonomy_menu_theme_suggestions_hierarchical_taxonomy_menu(array $variables) {
if (isset($variables['vocabularies'])) {
return array('hierarchical_taxonomy_menu__'.$variables['vocabularies']);
}
}

Thank you.

Feature request
Status

Fixed

Version

1.14

Component

Code

Created by

🇻🇳Vietnam lehoa85

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024