nice_menus.module in Nice Menus 8
Same filename and directory in other branches
Module to enable CSS dropdown and flyout menus.
Maintainer: Addison Berry (add1sun) Originally written by Jake Gordon (jakeg)
File
nice_menus.moduleView source
<?php
/**
* @file
* Module to enable CSS dropdown and flyout menus.
*
* Maintainer: Addison Berry (add1sun)
* Originally written by Jake Gordon (jakeg)
*/
use Drupal\Core\Menu\MenuTreeParameters;
/**
* Implements hook_help().
*/
function nice_menus_help($route_name) {
switch ($route_name) {
case 'help.page.nice_menus':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= t('Make drop down/flyout CSS menus for site and admin menus.');
$output .= t('<p>This is a simple module that enables the site to have drop down/flyout CSS menus for site and admin navigation.</p><p>Remember to activate and configure the menu blocks in <a href=":block_layout">Block layout</a></p>', array(
':block_layout' => '/admin/structure/block',
));
return $output;
}
}
/**
* Implements hook_theme().
*
* @param $existing
* @param $type
* @param $theme
* @param $path
*
* @return array
*/
function nice_menus_theme($existing, $type, $theme, $path) {
return array(
'nice_menus' => array(
'template' => 'nice_menus',
'variables' => array(
'menu_output' => NULL,
),
),
);
}
/**
* @param array $config
*
* @return mixed
*/
function nice_menus_build_tree(array $config) {
$menu_tree = \Drupal::service('menu.link_tree');
$parameters = new MenuTreeParameters();
// Set the active trail.
$active_trail = \Drupal::service('menu.active_trail')
->getActiveTrailIds($config['menu_name']);
$parameters
->setActiveTrail($active_trail);
// set menu root.
if ($config['menu_mlid']) {
$parameters
->setRoot($config['menu_mlid']);
}
// set menu depth.
if ($config['nice_menus_depth'] > 0) {
$parameters
->setMaxDepth($config['nice_menus_depth']);
}
// TODO support nice_menus_respect_expand.
$parameters
->excludeRoot()
->onlyEnabledLinks();
$tree = $menu_tree
->load($config['menu_name'], $parameters);
$manipulators = array(
array(
'callable' => 'menu.default_tree_manipulators:checkAccess',
),
array(
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
),
);
$tree = $menu_tree
->transform($tree, $manipulators);
return $menu_tree
->build($tree);
}
Functions
Name | Description |
---|---|
nice_menus_build_tree | |
nice_menus_help | Implements hook_help(). |
nice_menus_theme | Implements hook_theme(). |