You are here

public function HoneypotSettingsController::submitForm in Honeypot 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/HoneypotSettingsController.php \Drupal\honeypot\Controller\HoneypotSettingsController::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/Controller/HoneypotSettingsController.php, line 318

Class

HoneypotSettingsController
Returns responses for Honeypot module routes.

Namespace

Drupal\honeypot\Controller

Code

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

  // Save all the Honeypot configuration items from $form_state.
  foreach ($form_state
    ->getValues() as $key => $value) {
    if (in_array($key, $storage['keys'])) {
      $config
        ->set($key, $value);
    }
  }

  // Save the honeypot forms from $form_state into a 'form_settings' array.
  $config
    ->set('form_settings', $form_state
    ->getValue('form_settings'));
  $config
    ->save();

  // Clear the honeypot protected forms cache.
  $this->cache
    ->delete('honeypot_protected_forms');

  // Tell the user the settings have been saved.
  $this->messenger
    ->addMessage($this
    ->t('The configuration options have been saved.'));
}