You are here

public function SettingsForm::submitForm in Warmer 8

Same name and namespace in other branches
  1. 2.x src/Form/SettingsForm.php \Drupal\warmer\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 93

Class

SettingsForm
Settings form for the warmer module.

Namespace

Drupal\warmer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $warmers = $this->warmerManager
    ->getWarmers();
  array_map(function (WarmerPluginBase $warmer) use (&$form, $form_state) {
    $id = $warmer
      ->getPluginId();
    $subform_state = SubformState::createForSubform($form[$id], $form, $form_state);
    $warmer
      ->submitConfigurationForm($form[$id], $subform_state);
  }, $warmers);
  $name = $this
    ->getEditableConfigNames();
  $config_name = reset($name);
  $config = $this
    ->configFactory()
    ->getEditable($config_name);
  $warmer_configs = array_reduce($warmers, function ($carry, WarmerPluginBase $warmer) {
    $carry[$warmer
      ->getPluginId()] = $warmer
      ->getConfiguration();
    return $carry;
  }, []);
  $config
    ->set('warmers', $warmer_configs);
  $config
    ->save();
  $message = $this
    ->t('Settings saved for plugin(s): %names', [
    '%names' => implode(', ', array_map(function (WarmerPluginBase $warmer) {
      return $warmer
        ->getPluginDefinition()['label'];
    }, $warmers)),
  ]);
  $this
    ->messenger()
    ->addStatus($message);
}