updateLockedLanguageWeights example

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]]));
  }

}


  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $language_manager = \Drupal::languageManager();
    $language_manager->reset();
    if (!$this->isLocked() && $language_manager instanceof ConfigurableLanguageManagerInterface && !$this->isSyncing()) {
      $language_manager->updateLockedLanguageWeights();
    }

    // Update URL Prefixes for all languages after the     // LanguageManagerInterface::getLanguages() cache is flushed.     language_negotiation_url_prefixes_update();

    // If after adding this language the site will become multilingual, we need     // to rebuild language services.     if (!$this->preSaveMultilingual && !$update && $language_manager instanceof ConfigurableLanguageManagerInterface) {
      $language_manager::rebuildServices();
    }
    
Home | Imprint | This part of the site doesn't use cookies.