You are here

function template_preprocess_sidr_trigger in Sidr: Accessible Mobile Menus 8.2

Same name and namespace in other branches
  1. 8.3 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) {
  $settings = \Drupal::config('sidr.settings');
  $sidr_theme = $settings
    ->get('sidr_theme');
  $configuration = $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 ($configuration['trigger_icon']) {
    $attributes['class'][] = 'has-icon';
    $variables['trigger_icon'] = [
      '#markup' => $configuration['trigger_icon'],
    ];
  }

  // Prepare trigger text.
  if ($configuration['trigger_text']) {
    $attributes['class'][] = 'has-text';
    $variables['trigger_text'] = [
      '#markup' => $configuration['trigger_text'],
    ];
  }

  // Attach libraries.
  $variables['#attached'] = [
    'library' => [
      'sidr/behaviors',
      'sidr/sidr.' . $sidr_theme,
    ],
  ];
}