Same name and namespace in other branches
  1. 8.9.x core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::postSave()
  2. 9 core/modules/language/src/Entity/ConfigurableLanguage.php \Drupal\language\Entity\ConfigurableLanguage::postSave()

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides EntityBase::postSave

File

core/modules/language/src/Entity/ConfigurableLanguage.php, line 134

Class

ConfigurableLanguage
Defines the ConfigurableLanguage entity.

Namespace

Drupal\language\Entity

Code

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();
  }
  if (!$update) {

    // Install any available language configuration overrides for the language.
    \Drupal::service('language.config_factory_override')
      ->installLanguageOverrides($this
      ->id());
  }
  if (!$this
    ->isLocked() && !$update) {

    // Add language to the list of language domains.
    $config = \Drupal::configFactory()
      ->getEditable('language.negotiation');
    $domains = $config
      ->get('url.domains');
    $domains[$this
      ->id()] = '';
    $config
      ->set('url.domains', $domains)
      ->save(TRUE);
  }
}