function template_preprocess_sidr_trigger in Sidr: Accessible Mobile Menus 8.3
Same name and namespace in other branches
- 8.2 sidr.module \template_preprocess_sidr_trigger()
Implements template_preprocess_HOOK().
File
- ./
sidr.module, line 48 - Hooks and callbacks for the Sidr module.
Code
function template_preprocess_sidr_trigger(&$variables) {
$sidr_settings = \Drupal::config('sidr.settings');
$block_config = $variables['configuration'];
$attributes =& $variables['attributes'];
// Prepare trigger attributes.
$attributes['data-sidr-options'] = json_encode($variables['options']);
$attributes['class'] = [
'sidr-trigger',
'js-sidr-trigger',
];
// Prepare trigger icon.
if ($block_config['trigger_icon']) {
$attributes['class'][] = 'has-icon';
$variables['trigger_icon'] = [
'#markup' => $block_config['trigger_icon'],
];
}
// Prepare trigger text.
if ($block_config['trigger_text']) {
$attributes['class'][] = 'has-text';
$variables['trigger_text'] = [
'#markup' => $block_config['trigger_text'],
];
}
// Attach libraries.
$variables['#attached'] = [
'library' => [
'sidr/behaviors',
'sidr/sidr.' . $sidr_settings
->get('sidr_theme'),
],
'drupalSettings' => [
'sidr' => [
'closeOnBlur' => $sidr_settings
->get('close_on_blur'),
'closeOnEscape' => $sidr_settings
->get('close_on_escape'),
],
],
];
}