You are here

public function SettingsForm::submitForm in Responsive and off-canvas menu 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()
  2. 4.4.x src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()
  3. 4.0.x src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()
  4. 4.1.x src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()
  5. 4.3.x src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/SettingsForm.php, line 272

Class

SettingsForm
Form builder for the responsive_menu admin settings page.

Namespace

Drupal\responsive_menu\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  // Save all the submitted form values into config.
  \Drupal::configFactory()
    ->getEditable('responsive_menu.settings')
    ->set('horizontal_menu', $values['horizontal_menu'])
    ->set('horizontal_depth', $values['horizontal_depth'])
    ->set('horizontal_wrapping_element', $values['horizontal_wrapping_element'])
    ->set('use_breakpoint', $values['use_breakpoint'])
    ->set('include_css', $values['css'])
    ->set('extension_keyboard', $values['extension_keyboard'])
    ->set('allow_admin', $values['allow_admin'])
    ->set('wrapper_admin', $values['wrapper_admin'])
    ->set('wrapper_theme', $values['wrapper_theme'])
    ->set('pagedim', $values['pagedim'])
    ->set('off_canvas_menus', $values['off_canvas_menus'])
    ->set('off_canvas_position', $values['position'])
    ->set('off_canvas_theme', $values['theme'])
    ->set('horizontal_superfish', $values['superfish'])
    ->set('horizontal_superfish_delay', $values['superfish_delay'])
    ->set('horizontal_superfish_speed', $values['superfish_speed'])
    ->set('horizontal_superfish_speed_out', $values['superfish_speed_out'])
    ->set('horizontal_superfish_hoverintent', $values['superfish_hoverintent'])
    ->set('hammerjs', $values['hammerjs'])
    ->save();

  // Handle the breakpoint.
  $queries = responsive_menu_get_breakpoints();

  // Check if the breakpoint exists and the user has chosen
  // to use a breakpoint.
  if ($values['use_breakpoint'] && 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'])
      ->set('horizontal_media_query', $queries[$values['horizontal_breakpoint']])
      ->save();

    // Generate the breakpoint css file and remove existing one.
    $path = _get_breakpoint_css_filepath();

    // Ensure the directory exists, if not create it.
    if (file_exists($path . RESPONSIVE_MENU_BREAKPOINT_FILENAME)) {
      unlink($path . RESPONSIVE_MENU_BREAKPOINT_FILENAME);
    }
    $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([
    'config:block.block.horizontalmenu',
  ]);
  parent::submitForm($form, $form_state);
}