function template_preprocess_ultimenu in Ultimenu 8.2
Same name and namespace in other branches
- 8 ultimenu.theme.inc \template_preprocess_ultimenu()
- 7 templates/ultimenu.theme.inc \template_preprocess_ultimenu()
Prepares variables for ultimenu templates.
Default template: ultimenu.html.twig.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties of the element.
Properties used: #config, #items, #plugin_id, #attributes.
- config: The available config related to this particular instance.
- items: An array of available items.
- attributes: An associative array of attributes to be placed in the UL tag.
See also
File
- ./
ultimenu.theme.inc, line 26 - Preprocessors and theme functions of Ultimenu module.
Code
function template_preprocess_ultimenu(array &$variables) {
$element = $variables['element'];
foreach ([
'config',
'items',
] as $key) {
$variables[$key] = isset($element["#{$key}"]) ? $element["#{$key}"] : [];
}
$config = $variables['config'];
$variables['goodies'] = $goodies = ultimenu()
->getSetting('goodies');
$variables['attributes'] = new Attribute();
$variables['attributes']['id'] = 'ultimenu-' . $config['menu_name'];
$variables['attributes']['data-ultimenu'] = $config['menu_name'];
if (!empty($config['ajaxify'])) {
$variables['attributes']['data-ultiajax'] = TRUE;
}
$classes = isset($variables['attributes']['class']) ? $variables['attributes']['class'] : [];
if ($config['menu_name'] == 'main') {
// Makes Ultimenu hoverable if off-canvas is not enabled for all devices.
if (empty($goodies['off-canvas-all'])) {
$classes[] = 'ultimenu--hover';
}
}
else {
// Other Ultimenu is always hoverable for desktop.
$classes[] = 'ultimenu--hover';
}
$variables['attributes']['class'] = array_merge([
'ultimenu',
], $classes);
}