You are here

public function SettingsForm::submitForm in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/SettingsForm.php \Drupal\textimage\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 186

Class

SettingsForm
Main Textimage settings admin form.

Namespace

Drupal\textimage\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('textimage.settings');

  // Redirect to cleanup if required.
  if ($form_state
    ->getTriggeringElement()['#name'] == 'flush_all') {
    $form_state
      ->setRedirect('textimage.flush_all');
    return;
  }

  // Main settings.
  $font_plugin = $this->fontManager
    ->getPlugin($this
    ->config('image_effects.settings')
    ->get('font_selector.plugin_id'));
  $config
    ->set('default_extension', $form_state
    ->getValue([
    'settings',
    'main',
    'default_extension',
  ]))
    ->set('default_font.name', $font_plugin
    ->getDescription($form_state
    ->getValue([
    'settings',
    'main',
    'default_font_uri',
  ])))
    ->set('default_font.uri', $form_state
    ->getValue([
    'settings',
    'main',
    'default_font_uri',
  ]));

  // URL generation.
  $config
    ->set('url_generation.enabled', $form_state
    ->getValue([
    'settings',
    'url_generation',
    'enabled',
  ]))
    ->set('url_generation.text_separator', $form_state
    ->getValue([
    'settings',
    'url_generation',
    'text_separator',
  ]));

  // Maintenance.
  $config
    ->set('debug', $form_state
    ->getValue([
    'settings',
    'maintenance',
    'debug',
  ]));
  $config
    ->save();
  parent::submitForm($form, $form_state);
}