You are here

public function Settings::submitForm in Avatar Kit 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 ConfigFormBase::submitForm

File

src/Form/Settings.php, line 201

Class

Settings
Configure avatar kit settings.

Namespace

Drupal\avatars\Form

Code

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

  // Generators are already sorted correctly.
  foreach ($form_state
    ->getValue('avatar_generators') as $id => $row) {

    /** @var \Drupal\avatars\AvatarGeneratorInterface $avatar_generator */
    $avatar_generator = AvatarGenerator::load($id);
    $avatar_generator
      ->setStatus($row['enabled'])
      ->setWeight($row['weight'])
      ->save();
  }
  Cache::invalidateTags([
    'avatar_preview',
  ]);
  $intervals = $form_state
    ->getValue('refresh_interval');
  if ($intervals['static'] == UnlimitedNumber::UNLIMITED) {
    $intervals['static'] = 0;
  }
  $config
    ->set('refresh_interval', [
    'dynamic' => $intervals['dynamic'],
    'static' => $intervals['static'],
  ]);
  $config
    ->save();
  $this
    ->messenger()
    ->addStatus(t('Settings saved.'));
}