You are here

function template_preprocess_tb_megamenu_column in The Better Mega Menu 2.x

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

Prepare variables for tb_megamenu_column.

Parameters

array $vars: Variables are declared in theme.

File

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

Code

function template_preprocess_tb_megamenu_column(array &$vars) {
  $col = $vars['col']['col_content'];
  $col_config = isset($vars['col']['col_config']) ? $vars['col']['col_config'] : [];
  \Drupal::service('tb_megamenu.menu_builder')
    ->editColumnConfig($col_config);
  $vars['col_config'] = $col_config;
  $vars['close_button'] = FALSE;
  $vars['tb_items'] = [];
  $vars['attributes'] = new Attribute();
  foreach ($col as $tb_item) {
    if ($tb_item['type'] == 'menu_item') {
      $vars['tb_items'][] = [
        '#theme' => 'tb_megamenu_subnav',
        '#menu_name' => $vars['menu_name'],
        '#col' => $col,
        '#items' => $vars['parent']->subtree,
        '#level' => $vars['level'],
        '#menu_config' => $vars['menu_config'],
        '#block_config' => $vars['block_config'],
        '#trail' => $vars['trail'],
        '#section' => $vars['section'],
      ];
      break;
    }
    else {
      $vars['tb_items'][] = [
        '#theme' => 'tb_megamenu_block',
        '#block_id' => $tb_item['block_id'],
        '#section' => $vars['section'],
        '#showblocktitle' => $col_config['showblocktitle'],
      ];
      $vars['attributes']['data-showblocktitle'] = $col_config['showblocktitle'];
      if ($vars['section'] !== 'frontend') {
        $msg = t("Remove this block");
        $vars['close_button'] = [
          '#markup' => '<span class="close fa fa-times-circle" title="' . $msg . '">&nbsp;</span>',
        ];
      }
    }
  }
  $vars['attributes']['class'] = [];
  $theme_name = str_replace('_', '-', $vars['theme_hook_original']);
  $vars['attributes']['class'][] = $theme_name;
  $vars['attributes']['class'][] = 'span' . $col_config['width'];
  $vars['attributes']['class'][] = 'mega-col-nav';
  if (!empty($col_config['class'])) {
    $vars['attributes']['class'][] = $col_config['class'];
  }
  if (!empty($col_config['hidewcol'])) {
    $vars['attributes']['class'][] = $col_config['class'];
    $vars['attributes']['class'][] = 'hidden-collapse';
  }
  $vars['attributes']['data-class'] = $col_config['class'];
  $vars['attributes']['data-width'] = $col_config['width'];
  $vars['attributes']['data-hidewcol'] = $col_config['hidewcol'];
  $num_cols = isset($vars['block_config']['number-columns']) ? $vars['block_config']['number-columns'] : 1;
  $vars['attributes']['id'] = \Drupal::service('tb_megamenu.menu_builder')
    ->getIdColumn($num_cols);
}