You are here

public function LanguageListBuilder::submitForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/language/src/LanguageListBuilder.php \Drupal\language\LanguageListBuilder::submitForm()
  2. 9 core/modules/language/src/LanguageListBuilder.php \Drupal\language\LanguageListBuilder::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 DraggableListBuilder::submitForm

File

core/modules/language/src/LanguageListBuilder.php, line 155

Class

LanguageListBuilder
Defines a class to build a listing of language entities.

Namespace

Drupal\language

Code

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

  // Save the default language if changed.
  $new_id = $form_state
    ->getValue('site_default_language');
  if ($new_id != $this->languageManager
    ->getDefaultLanguage()
    ->getId()) {
    $this->configFactory
      ->getEditable('system.site')
      ->set('default_langcode', $new_id)
      ->save();
    $this->languageManager
      ->reset();
  }
  if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
    $this->languageManager
      ->updateLockedLanguageWeights();
  }
  $this->messenger
    ->addStatus($this
    ->t('Configuration saved.'));

  // Force the redirection to the page with the language we have just
  // selected as default.
  $form_state
    ->setRedirectUrl($this->entities[$new_id]
    ->toUrl('collection', [
    'language' => $this->entities[$new_id],
  ]));
}