function mie_demo_base_preprocess in Menu Item Extras 8.2
Implements hook_preprocess().
File
- modules/
mie_demo_base/ mie_demo_base.module, line 46 - Manage fields for the menu items.
Code
function mie_demo_base_preprocess(&$variables, $hook, &$info) {
$module_path = drupal_get_path('module', 'mie_demo_base');
if ($hook == 'menu') {
if (substr($info['theme path'], 0, 7) != 'themes/') {
$info['theme path'] = $module_path;
$info['path'] = $module_path . '/templates';
}
}
if ($hook == 'menu_link_content') {
/* @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content */
$menu_link_content = $variables['elements']['#menu_link_content'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
if (substr($info['theme path'], 0, 7) !== 'themes/' && $menu_link_content
->getMenuName() === 'mie-demo-base-menu') {
$info['theme path'] = $module_path;
$info['path'] = $module_path . '/templates';
$info['template'] = 'menu-link-content--' . $menu_link_content
->getMenuName() . '--' . $sanitized_view_mode;
if (isset($variables['elements']['#menu_level']) && $variables['elements']['#menu_level'] === 0) {
$info['template'] = 'menu-link-content--' . $menu_link_content
->getMenuName() . '--' . 'menu-level-' . $variables['elements']['#menu_level'] . '--' . $sanitized_view_mode;
}
if ($sanitized_view_mode === 'banner' && isset($variables['elements']['#menu_level']) && $variables['elements']['#menu_level'] === 1) {
$info['template'] = 'menu-link-content--' . $menu_link_content
->getMenuName() . '--' . 'menu-level-' . $variables['elements']['#menu_level'] . '--' . $sanitized_view_mode;
}
}
}
if ($hook === 'taxonomy_term') {
/* @var \Drupal\taxonomy\Entity\Term $entity */
$entity = $variables['elements']['#taxonomy_term'];
if ($entity
->bundle() === 'mie_demo_content') {
$info['theme path'] = $module_path;
$info['path'] = $module_path . '/templates';
$info['template'] = 'taxonomy-term--mie-demo-content';
}
}
}