You are here

public function SettingsForm::submitForm in Responsive and off-canvas menu 4.4.x

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\responsive_menu\Form\SettingsForm::submitForm()
  2. 8.2 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 324

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.
  $this->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('allow_admin', $values['allow_admin'])
    ->set('use_bootstrap', $values['use_bootstrap'])
    ->set('wrapper_admin', $values['wrapper_admin'])
    ->set('wrapper_theme', $values['wrapper_theme'])
    ->set('use_polyfills', $values['use_polyfills'])
    ->set('pagedim', $values['pagedim'])
    ->set('modify_viewport', $values['modify_viewport'])
    ->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('drag', $values['drag'])
    ->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.
    $this->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 = $this->config
      ->get('horizontal_media_query');
    responsive_menu_generate_breakpoint_css($breakpoint);
  }

  // Invalidate the offcanvas preRender result so these settings get
  // applied when rebuilding the page. Fixes #3134331.
  Cache::invalidateTags([
    'offcanvas_render',
    'horizontal_menu',
  ]);
  parent::submitForm($form, $form_state);
}