You are here

public function AnimationsConfigForm::submitForm in Animations (JS/CSS) 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 FormInterface::submitForm

File

src/Form/AnimationsConfigForm.php, line 150

Class

AnimationsConfigForm

Namespace

Drupal\animations\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // get editibale instance of the module config
  $config = \Drupal::service('config.factory')
    ->getEditable('animations.config');

  // loop and save the new values in the module config
  foreach ($form_state
    ->getValues() as $key => $value) {

    // check if the field name is present in the config - because not all submitted fields are css selectors
    if (is_array($config
      ->get('animations.' . $key . '.classes'))) {

      // explode the input string back to array
      $config
        ->set('animations.' . $key . '.classes', explode("\n", $form_state
        ->getValue($key)));
    }
  }
  $config
    ->save();
}