You are here

function responsive_menus_page_attachments in Responsive Menus 8

Implements hook_page_attachments().

File

./responsive_menus.module, line 210
Responsify menus in Drupal.

Code

function responsive_menus_page_attachments(array &$attachements) {
  $config = \Drupal::config('responsive_menus.configuration');

  // Load our style.
  if (!isset($style)) {
    $ignore_admin = $config
      ->get('ignore_admin');
    $path_is_admin = \Drupal::service('router.admin_context')
      ->isAdminRoute();
    if ($ignore_admin && $path_is_admin) {
      return;
    }
    $style = $config
      ->get('style');
  }

  //  $jq_update_ignore = variable_get('responsive_menus_no_jquery_update', array(1 => 0));
  //  $style_info = responsive_menus_style_load($style, $jq_update_ignore);
  $plugin_manager = \Drupal::service('plugin.manager.responsive_menus');

  /** @var \Drupal\responsive_menus\ResponsiveMenusPluginInterface $style_plugin */
  $style_plugin = $plugin_manager
    ->createInstance($style, [
    'settings' => $config
      ->get('style_settings'),
  ]);
  if (!$style_plugin) {
    return;
  }
  $data =& drupal_static(__FUNCTION__, array());
  if (!isset($data['execute_index'])) {
    $data['execute_index'] = -1;
  }
  $data['execute_index']++;

  // Add library.
  $attachements['#attached']['library'][] = $style_plugin
    ->getPluginDefinition()['library'];

  // Add JS settings.
  $js_settings[$data['execute_index']] = $style_plugin
    ->getJsSettings();
  $js_settings[$data['execute_index']]['responsive_menus_style'] = $style;
  \Drupal::moduleHandler()
    ->alter('responsive_menus_execute', $js_settings);
  $attachements['#attached']['drupalSettings']['responsive_menus'] = $js_settings;
}