You are here

function template_preprocess_menu__uikit_nav in UIkit Components 8.3

Implements template_preprocess_HOOK() for menu--uikit-nav.html.twig.

File

includes/preprocess.inc, line 540
Set up variables to be placed within the template (.html.twig) files.

Code

function template_preprocess_menu__uikit_nav(&$variables) {
  $menu_name = $variables['menu_name'];
  $menu_style = UIkitComponents::getMenuStyle($menu_name);
  $nav_style_modifier = UIkitComponents::getNavStyleModifier($menu_name);
  $nav_center = UIkitComponents::getNavCenterModifier($menu_name);
  $nav_width_classes = UIkitComponents::getNavWidthClasses($menu_name);
  $attributes = new Attribute();
  $wrapper_attributes = new Attribute();
  if ($menu_style) {
    $attributes
      ->addClass('uk-nav');
    if ($nav_style_modifier) {
      $attributes
        ->addClass($nav_style_modifier);
    }
    if ($nav_center) {
      $attributes
        ->addClass('uk-nav-center');
    }
    foreach ($variables['items'] as $index => $item) {
      if ($item['below']) {
        $variables['items'][$index]['attributes']
          ->addClass('uk-parent');
      }
    }
  }
  if ($nav_width_classes) {
    $classes = explode(' ', $nav_width_classes);
    foreach ($classes as $class) {
      $wrapper_attributes
        ->addClass($class);
    }
  }
  $variables['attributes'] = $attributes;
  $variables['wrapper_attributes'] = $wrapper_attributes;
}