function template_preprocess_we_megamenu_backend in Drupal Mega Menu 8.x
Same name and namespace in other branches
- 8 we_megamenu.module \template_preprocess_we_megamenu_backend()
Parameters
array $vars: Variables are declared in theme.
File
- ./
we_megamenu.module, line 153 - Drupal 8 Mega Menu Module.
Code
function template_preprocess_we_megamenu_backend(array &$vars) {
ini_set('xdebug.max_nesting_level', 1024);
$menu_name = $vars['menu_name'];
$block_theme = $vars['block_theme'];
$data_config = WeMegaMenuBuilder::loadConfig($menu_name, $block_theme);
if (empty($data_config)) {
$data_config = WeMegaMenuBuilder::initMegamenu($menu_name, $block_theme);
}
else {
if (isset($data_config->menu_update_flag) && $data_config->menu_update_flag) {
// drupal_flush_all_caches();
$theme_name = $block_theme;
$menu_items = WeMegaMenuBuilder::getMenuTreeOrder($menu_name, FALSE);
WeMegaMenuBuilder::updateMegamenuFromDrupalMenu($data_config, $menu_items, 0);
$data_config->menu_update_flag = 0;
WeMegaMenuBuilder::saveConfig($menu_name, $theme_name, json_encode($data_config));
// drupal_flush_all_caches();
}
}
$block_config = isset($data_config->block_config) ? $data_config->block_config : [];
$menu_items = WeMegaMenuBuilder::getMenuTreeOrder($menu_name, TRUE);
$trail = WeMegaMenuBuilder::buildPageTrail($menu_items);
$vars['content'] = [
'#theme' => 'we_megamenu_ul',
'#items' => $menu_items,
'#data_config' => $data_config ? $data_config : NULL,
'#section' => $vars['section'],
'#block_theme' => $vars['block_theme'],
'#menu_name' => $vars['menu_name'],
'#trail' => $trail,
];
$vars['attributes'] = new Attribute();
$vars['attributes']['class'] = [];
$vars['attributes']['class'][] = $menu_name;
$vars['attributes']['class'][] = 'navbar';
$vars['attributes']['class'][] = 'navbar-default';
$vars['attributes']['class'][] = 'navbar-we-mega-menu';
$vars['attributes']['class'][] = $vars['section'];
$vars['attributes']['class'][] = isset($data_config->block_config->{'auto-mobile-collapse'}) == 1 ? 'mobile-collapse' : '';
$vars['attributes']['data-menu-name'] = $menu_name;
$vars['attributes']['data-block-theme'] = $block_theme;
$vars['attributes']['data-style'] = isset($data_config->block_config->style) ? $data_config->block_config->style : 'Default';
$vars['attributes']['data-animation'] = isset($data_config->block_config->animation) ? $data_config->block_config->animation : 'None';
$vars['attributes']['data-delay'] = isset($data_config->block_config->delay) ? $data_config->block_config->delay : '';
$vars['attributes']['data-duration'] = isset($data_config->block_config->duration) ? $data_config->block_config->duration : '';
$vars['attributes']['data-autoarrow'] = isset($data_config->block_config->{'auto-arrow'}) ? $data_config->block_config->{'auto-arrow'} : '';
$vars['attributes']['data-alwayshowsubmenu'] = isset($data_config->block_config->{'always-show-submenu'}) ? $data_config->block_config->{'always-show-submenu'} : '';
$vars['attributes']['data-action'] = isset($data_config->block_config->action) ? $data_config->block_config->action : 'hover';
$vars['attributes']['data-mobile-collapse'] = isset($data_config->block_config->{'auto-mobile-collapse'}) ? $data_config->block_config->{'auto-mobile-collapse'} : 0;
}