You are here

public function ShrinkTheWebSettingsForm::submitForm in ShrinkTheWeb 8

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/ShrinkTheWebSettingsForm.php, line 396

Class

ShrinkTheWebSettingsForm

Namespace

Drupal\shrinktheweb\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('shrinktheweb.settings');
  if ($config
    ->get('shrinktheweb_cache_days') != '-1' && $form_state
    ->getValue('shrinktheweb_refresh_thumbnails') != TRUE) {
    module_load_include('inc', 'shrinktheweb', 'shrinktheweb.api');
    shrinktheweb_deleteAllImages();
  }
  entity_render_cache_clear();
  $config
    ->set('shrinktheweb_access_key', $form_state
    ->getValue('shrinktheweb_access_key'))
    ->set('shrinktheweb_secret_key', $form_state
    ->getValue('shrinktheweb_secret_key'))
    ->set('shrinktheweb_thumb_size_custom', $form_state
    ->getValue('shrinktheweb_thumb_size_custom'))
    ->set('shrinktheweb_max_height', $form_state
    ->getValue('shrinktheweb_max_height'))
    ->set('shrinktheweb_native_res', $form_state
    ->getValue('shrinktheweb_native_res'))
    ->set('shrinktheweb_widescreen_y', $form_state
    ->getValue('shrinktheweb_widescreen_y'))
    ->set('shrinktheweb_delay', $form_state
    ->getValue('shrinktheweb_delay'))
    ->set('shrinktheweb_quality', $form_state
    ->getValue('shrinktheweb_quality'))
    ->set('shrinktheweb_custom_msg_url', $form_state
    ->getValue('shrinktheweb_custom_msg_url'))
    ->set('shrinktheweb_token', $form_state
    ->getValue('shrinktheweb_token'))
    ->set('shrinktheweb_full_size', $form_state
    ->getValue('shrinktheweb_full_size'));

  //Make default settings not to be overriden by the form submits before access and secret keys were set
  if ($form_state
    ->getValue('shrinktheweb_thumb_size') != '') {
    $config
      ->set('shrinktheweb_thumb_size', $form_state
      ->getValue('shrinktheweb_thumb_size'));
  }
  if ($form_state
    ->getValue('shrinktheweb_cache_days') != '') {
    $config
      ->set('shrinktheweb_cache_days', $form_state
      ->getValue('shrinktheweb_cache_days'));
  }
  if ($form_state
    ->getValue('shrinktheweb_thumbs_folder') != '') {
    $config
      ->set('shrinktheweb_thumbs_folder', $form_state
      ->getValue('shrinktheweb_thumbs_folder'));
  }
  if ($form_state
    ->getValue('shrinktheweb_debug') != '') {
    $config
      ->set('shrinktheweb_debug', $form_state
      ->getValue('shrinktheweb_debug'));
  }
  if ($form_state
    ->getValue('shrinktheweb_notifynopush') != '') {
    $config
      ->set('shrinktheweb_notifynopush', $form_state
      ->getValue('shrinktheweb_notifynopush'));
  }
  if ($form_state
    ->getValue('shrinktheweb_enable_https') != '') {
    $config
      ->set('shrinktheweb_enable_https', $form_state
      ->getValue('shrinktheweb_enable_https'));
  }
  $config
    ->save();
  if (method_exists($this, '_submitForm')) {
    $this
      ->_submitForm($form, $form_state);
  }
  parent::submitForm($form, $form_state);
}