You are here

public function AutocompletionConfigurationListBuilder::submitForm in Search Autocomplete 2.x

Same name and namespace in other branches
  1. 8 src/Controller/AutocompletionConfigurationListBuilder.php \Drupal\search_autocomplete\Controller\AutocompletionConfigurationListBuilder::submitForm()

Implements \Drupal\Core\Form\FormInterface::submitForm().

Form submission handler for the main block administration form.

Overrides FormInterface::submitForm

File

src/Controller/AutocompletionConfigurationListBuilder.php, line 119

Class

AutocompletionConfigurationListBuilder
Provides a listing of autocompletion_configuration entities.

Namespace

Drupal\search_autocomplete\Controller

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  // Save global configurations.
  Drupal::configFactory()
    ->getEditable('search_autocomplete.settings')
    ->set('admin_helper', $values['admin_helper'])
    ->save();

  // Save all configuration activations.
  $entities = $this->storage
    ->loadMultiple(array_keys($form_state
    ->getValue('configs')));
  foreach ($entities as $entity_id => $entity) {
    $entity_values = $form_state
      ->getValue([
      'configs',
      $entity_id,
    ]);
    $entity
      ->setStatus($entity_values['enabled']);
    $entity
      ->save();
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('Data have been saved. You may have to %clear_caches for theses changes to apply.', [
    '%clear_caches' => Link::fromTextAndUrl(t('Clear all caches'), Url::fromRoute('system.performance_settings'))
      ->toString(),
  ]));
}