ultimenu.module in Ultimenu 8.2
Same filename and directory in other branches
Build Ultimenu blocks based on menu, and their regions on enabled menu items.
File
ultimenu.moduleView source
<?php
/**
* @file
* Build Ultimenu blocks based on menu, and their regions on enabled menu items.
*/
use Drupal\Core\Extension\Extension;
/**
* Provides a convenient shortcut for procedural hooks.
*
* @return class
* The Ultimenu class instances.
*/
function ultimenu($key = 'manager') {
static $manager;
static $skin;
if (!isset($manager)) {
$manager = \Drupal::service('ultimenu.manager');
}
switch ($key) {
case 'skin':
if (!isset($skin)) {
$skin = \Drupal::service('ultimenu.skin');
}
return $skin;
default:
return $manager;
}
}
/**
* Implements hook_theme().
*/
function ultimenu_theme($existing, $type, $theme, $path) {
return [
'ultimenu' => [
'render element' => 'element',
'file' => 'ultimenu.theme.inc',
],
];
}
/**
* Implements hook_library_info_build().
*/
function ultimenu_library_info_build() {
return ultimenu('skin')
->libraryInfoBuild();
}
/**
* Implements hook_library_info_alter().
*/
function ultimenu_library_info_alter(&$libraries, $extension) {
if ($extension === 'ultimenu') {
ultimenu()
->libraryInfoAlter($libraries, $extension);
}
}
/**
* Implements hook_system_info_alter().
*/
function ultimenu_system_info_alter(&$info, Extension $file, $type) {
if ($type == 'theme' && $file
->getName() == ultimenu()
->getThemeDefault() && isset($info['regions'])) {
if ($regions = ultimenu()
->getEnabledRegions()) {
// Append the Ultimenu regions into the theme defined regions.
foreach ($regions as $key => $region) {
$info['regions'] += [
$key => $region,
];
}
// Remove unwanted Ultimenu regions from theme .info if so configured.
if (($remove_regions = ultimenu()
->removeRegions()) !== FALSE) {
foreach ($remove_regions as $key => $region) {
unset($info['regions'][$key]);
}
}
}
}
}
/**
* Implements hook_themes_uninstalled().
*/
function ultimenu_themes_uninstalled($theme_list) {
ultimenu('skin')
->clearCachedDefinitions(TRUE);
}
/**
* Checks if we are using the default theme.
*/
function _ultimenu_is_applicable() {
static $applicable;
if (!isset($applicable)) {
$theme = \Drupal::theme()
->getActiveTheme()
->getName();
$applicable = ultimenu()
->getThemeDefault() == $theme;
}
return $applicable;
}
/**
* Implements hook_page_bottom().
*/
function ultimenu_page_bottom(array &$page_bottom) {
if (_ultimenu_is_applicable()) {
$label = t('Menu');
$button = '<button data-ultimenu-button="#ultimenu-main" class="button button--ultimenu"
aria-label="' . $label . '" value="' . $label . '"><span class="bars">' . $label . '</span></button>';
$page_bottom['ultimenu_button']['#markup'] = $button;
$page_bottom['ultimenu_button']['#allowed_tags'] = [
'button',
'span',
];
}
}
/**
* Implements hook_preprocess_html().
*/
function ultimenu_preprocess_html(&$variables) {
if (_ultimenu_is_applicable()) {
$variables['attributes']['class'][] = 'is-ultimenu-canvas';
// If off-canvas is enabled for both mobile and desktop, add `active`
// class, else it means menu item link is hoverable for desktop.
$active = ultimenu()
->getSetting('goodies.off-canvas-all') ? 'active' : 'hover';
$variables['attributes']['class'][] = 'is-ultimenu-canvas--' . $active;
}
}
/**
* Implements hook_help().
*/
function ultimenu_help($route_name) {
if ($route_name == 'help.page.ultimenu') {
$items = [
'README',
'CONFIGURATION',
'STYLING',
'TROUBLESHOOTING',
'UPDATING',
'FAQ',
'MAINTAINERS',
];
$output = '';
foreach ($items as $key) {
$output .= file_get_contents(dirname(__FILE__) . "/docs/{$key}.md");
}
return function_exists('blazy_parse_markdown') ? blazy_parse_markdown($output) : '<pre>' . $output . '</pre>';
}
return '';
}
Functions
Name![]() |
Description |
---|---|
ultimenu | Provides a convenient shortcut for procedural hooks. |
ultimenu_help | Implements hook_help(). |
ultimenu_library_info_alter | Implements hook_library_info_alter(). |
ultimenu_library_info_build | Implements hook_library_info_build(). |
ultimenu_page_bottom | Implements hook_page_bottom(). |
ultimenu_preprocess_html | Implements hook_preprocess_html(). |
ultimenu_system_info_alter | Implements hook_system_info_alter(). |
ultimenu_theme | Implements hook_theme(). |
ultimenu_themes_uninstalled | Implements hook_themes_uninstalled(). |
_ultimenu_is_applicable | Checks if we are using the default theme. |