You are here

public function SettingsForm::submitForm in Image Effects 8

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

Class

SettingsForm
Main image_effects settings admin form.

Namespace

Drupal\image_effects\Form

Code

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

  // Color plugin.
  $color_plugin = $this->colorManager
    ->getPlugin($form_state
    ->getValue([
    'settings',
    'color_selector',
    'plugin_id',
  ]));
  if ($form_state
    ->hasValue([
    'settings',
    'color_selector',
    'plugin_settings',
  ])) {
    $color_plugin
      ->setConfiguration($form_state
      ->getValue([
      'settings',
      'color_selector',
      'plugin_settings',
    ]));
  }
  $config
    ->set('color_selector.plugin_id', $color_plugin
    ->getPluginId())
    ->set('color_selector.plugin_settings.' . $color_plugin
    ->getPluginId(), $color_plugin
    ->getConfiguration());

  // Image plugin.
  $image_plugin = $this->imageManager
    ->getPlugin($form_state
    ->getValue([
    'settings',
    'image_selector',
    'plugin_id',
  ]));
  if ($form_state
    ->hasValue([
    'settings',
    'image_selector',
    'plugin_settings',
  ])) {
    $image_plugin
      ->setConfiguration($form_state
      ->getValue([
      'settings',
      'image_selector',
      'plugin_settings',
    ]));
  }
  $config
    ->set('image_selector.plugin_id', $image_plugin
    ->getPluginId())
    ->set('image_selector.plugin_settings.' . $image_plugin
    ->getPluginId(), $image_plugin
    ->getConfiguration());

  // Font plugin.
  $font_plugin = $this->fontManager
    ->getPlugin($form_state
    ->getValue([
    'settings',
    'font_selector',
    'plugin_id',
  ]));
  if ($form_state
    ->hasValue([
    'settings',
    'font_selector',
    'plugin_settings',
  ])) {
    $font_plugin
      ->setConfiguration($form_state
      ->getValue([
      'settings',
      'font_selector',
      'plugin_settings',
    ]));
  }
  $config
    ->set('font_selector.plugin_id', $font_plugin
    ->getPluginId())
    ->set('font_selector.plugin_settings.' . $font_plugin
    ->getPluginId(), $font_plugin
    ->getConfiguration());
  $config
    ->save();
  parent::submitForm($form, $form_state);
}