function menu_link_modal_set_attributes in Menu Link Modal 8
Same name and namespace in other branches
- 8.2 menu_link_modal.module \menu_link_modal_set_attributes()
Set the attributes on the given items.
Parameters
array $items: List of menu items.
bool $modal_link: Modal link: true if exist else false.
1 call to menu_link_modal_set_attributes()
- menu_link_modal_preprocess_menu in ./
menu_link_modal.module - Implements hook_preprocess_menu().
File
- ./
menu_link_modal.module, line 105 - Main file of Menu Link Modal module.
Code
function menu_link_modal_set_attributes(array &$items, &$modal_link) {
foreach ($items as &$item) {
$modal_info = $item['url']
->getOption('modal') ?? [];
if (!empty($modal_info)) {
$modal_link = TRUE;
$attributes = $item['url']
->getOption('attributes') ?: [];
$attributes['class'] = isset($attributes['class']) ? !is_array($attributes['class']) ? explode(' ', $attributes['class']) : $attributes['class'] : [];
$attributes['class'][] = 'use-ajax';
$attributes['data-dialog-type'] = 'modal';
$attributes['data-dialog-options'] = Json::encode([
'height' => $modal_info['height'],
'width' => $modal_info['width'],
]);
$item['url']
->setOption('attributes', $attributes);
}
if (!empty($item['below'])) {
menu_link_modal_set_attributes($item['below'], $modal_link);
}
}
}