/**
  * {@inheritdoc}
  */
 public function build()
 {
     $depth = \Drupal::config('responsive_menu.settings')->get('horizontal_depth');
     $menu_name = \Drupal::config('responsive_menu.settings')->get('horizontal_menu');
     $menu_tree = \Drupal::menuTree();
     $parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
     $parameters->setMaxDepth($depth);
     // Force the entire tree to be build be setting expandParents to an
     // empty array.
     $parameters->expandedParents = array();
     $tree = $menu_tree->load($menu_name, $parameters);
     $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
     $tree = $menu_tree->transform($tree, $manipulators);
     $menu = $menu_tree->build($tree);
     $menu['#theme'] = 'responsive_menu_horizontal';
     $output = array('#theme' => 'responsive_menu_block_wrapper', '#element_type' => \Drupal::config('responsive_menu.settings')->get('horizontal_wrapping_element'), '#content' => $menu);
     // Check whether the generated breakpoint css exists and if not create it.
     if (!file_exists(_get_breakpoint_css_filepath() . RESPONSIVE_MENU_BREAKPOINT_FILENAME)) {
         $breakpoint = \Drupal::config('responsive_menu.settings')->get('horizontal_media_query');
         responsive_menu_generate_breakpoint_css($breakpoint);
     }
     // Add the dynamically generated library with breakpoint styles.
     $output['#attached']['library'][] = 'responsive_menu/responsive_menu.breakpoint';
     // Add the module's css file if the user does not want to disable it.
     if (\Drupal::config('responsive_menu.settings')->get('include_css')) {
         $output['#attached']['library'][] = 'responsive_menu/responsive_menu.styling';
     }
     // Add the superfish library if the user has requested it.
     $superfish_setting = \Drupal::config('responsive_menu.settings')->get('horizontal_superfish');
     if ($superfish_setting) {
         $output['#attached']['library'][] = 'responsive_menu/responsive_menu.superfish';
     }
     // Add superfish's hoverIntent library if the user has requested it.
     if ($superfish_setting && \Drupal::config('responsive_menu.settings')->get('horizontal_superfish_hoverintent')) {
         $output['#attached']['library'][] = 'responsive_menu/responsive_menu.superfish_hoverintent';
     }
     // Add the hammerjs library if the user has requested it.
     $hammerjs_setting = \Drupal::config('responsive_menu.settings')->get('hammerjs');
     if ($hammerjs_setting) {
         $output['#attached']['library'][] = 'responsive_menu/responsive_menu.hammerjs';
     }
     // Add the javascript behaviours.
     $output['#attached']['library'][] = 'responsive_menu/responsive_menu.javascript';
     $output['#attached']['drupalSettings']['responsive_menu'] = array('position' => \Drupal::config('responsive_menu.settings')->get('off_canvas_position'), 'theme' => \Drupal::config('responsive_menu.settings')->get('off_canvas_theme'), 'breakpoint' => \Drupal::config('responsive_menu.settings')->get('horizontal_media_query'), 'superfish' => array('active' => \Drupal::config('responsive_menu.settings')->get('horizontal_superfish'), 'delay' => \Drupal::config('responsive_menu.settings')->get('horizontal_superfish_delay'), 'speed' => \Drupal::config('responsive_menu.settings')->get('horizontal_superfish_speed'), 'speedOut' => \Drupal::config('responsive_menu.settings')->get('horizontal_superfish_speed_out')));
     $media_query = \Drupal::config('responsive_menu.settings')->get('horizontal_media_query');
     // Attempt to clean up a media query in case it isn't properly enclosed in
     // brackets.
     $media_query = preg_replace('/^(min|max)(.+?)$/', '($1$2)', $media_query);
     $output['#attached']['drupalSettings']['responsive_menu']['mediaQuery'] = $media_query;
     return $output;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     // Save all the values into config.
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_menu', $values['horizontal_menu'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_depth', $values['horizontal_depth'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_wrapping_element', $values['horizontal_wrapping_element'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('include_css', $values['css'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('off_canvas_menus', $values['off_canvas_menus'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('off_canvas_position', $values['position'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('off_canvas_theme', $values['theme'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_superfish', $values['superfish'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_superfish_delay', $values['superfish_delay'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_superfish_speed', $values['superfish_speed'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_superfish_speed_out', $values['superfish_speed_out'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_superfish_hoverintent', $values['superfish_hoverintent'])->save();
     \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('hammerjs', $values['hammerjs'])->save();
     // Handle the breakpoint.
     $queries = responsive_menu_get_breakpoints();
     // Check if the breakpoint exists.
     if (isset($queries[$values['horizontal_breakpoint']])) {
         // Store the breakpoint for using again in the form.
         \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_breakpoint', $values['horizontal_breakpoint'])->save();
         // Also store the actual breakpoint string for use in calling the stylesheet.
         \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_media_query', $queries[$values['horizontal_breakpoint']])->save();
     } else {
         \Drupal::configFactory()->getEditable('responsive_menu.settings')->set('horizontal_media_query', $values['horizontal_media_query'])->save();
     }
     // Generate the breakpoint css file.
     $breakpoint = \Drupal::config('responsive_menu.settings')->get('horizontal_media_query');
     responsive_menu_generate_breakpoint_css($breakpoint);
     // Invalidate the block cache for the horizontal menu so these settings get
     // applied when rebuilding the block on view.
     Cache::invalidateTags(array('config:block.block.horizontalmenu'));
     parent::submitForm($form, $form_state);
 }