You are here

function template_preprocess_tb_megamenu_submenu in The Better Mega Menu 8

Same name and namespace in other branches
  1. 7 tb_megamenu.themes.inc \template_preprocess_tb_megamenu_submenu()
  2. 2.x tb_megamenu.module \template_preprocess_tb_megamenu_submenu()

Prepare variables for tb_megamenu_submenu.

Parameters

array $vars: Variables are declared in theme.

File

./tb_megamenu.module, line 317
TB Mega Menu.

Code

function template_preprocess_tb_megamenu_submenu(array &$vars) {
  $parent = $vars['parent'];
  $plugin_id = $parent->link
    ->getPluginId();
  $menu_config = $vars['menu_config'];
  $item_config = isset($menu_config[$plugin_id]) ? $menu_config[$plugin_id] : [];
  $submenu_config = isset($item_config['submenu_config']) ? $item_config['submenu_config'] : [];
  $vars['submenu_config'] = $submenu_config;
  \Drupal::service('tb_megamenu.menu_builder')
    ->editSubMenuConfig($submenu_config);
  $vars['rows'] = [];
  foreach ($item_config['rows_content'] as $row) {
    $vars['rows'][] = [
      '#theme' => 'tb_megamenu_row',
      '#menu_name' => $vars['menu_name'],
      '#row' => $row,
      '#parent' => $vars['parent'],
      '#level' => $vars['level'],
      '#menu_config' => $vars['menu_config'],
      '#block_config' => $vars['block_config'],
      '#trail' => $vars['trail'],
      '#section' => $vars['section'],
    ];
  }
  $vars['attributes'] = new Attribute();
  $vars['attributes']['class'] = [];
  $theme_name = str_replace('_', '-', $vars['theme_hook_original']);
  $vars['attributes']['class'][] = $theme_name;
  if ($submenu_config['class'] != "") {
    $vars['attributes']['class'][] = $submenu_config['class'];
  }
  if ($submenu_config['group']) {
    $vars['attributes']['class'][] = 'mega-group-ct';
  }
  else {
    $vars['attributes']['class'][] = 'dropdown-menu';
    $vars['attributes']['class'][] = 'mega-dropdown-menu';
  }
  $vars['attributes']['class'][] = 'nav-child';
  $vars['attributes']['data-class'] = $submenu_config['class'];
  $vars['attributes']['data-width'] = $submenu_config['width'];
  if (!empty($submenu_config['width'])) {
    $vars['attributes']['style'] = "width: " . $submenu_config['width'] . "px;";
  }

  // Add a11y attributes.
  $vars['attributes']['role'] = 'list';
}