Esempio n. 1
0
 /**
  * Causes the container to be rebuilt on the next request.
  *
  * This event subscriber assumes that the new default langcode and old default
  * langcode are valid langcodes. If the schema definition of either
  * system.site:default_langcode or language.negotiation::url.prefixes changes
  * then this event must be changed to work with both the old and new schema
  * definition so this event is update safe.
  *
  * @param ConfigCrudEvent $event
  *   The configuration event.
  */
 public function onConfigSave(ConfigCrudEvent $event)
 {
     $saved_config = $event->getConfig();
     if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) {
         $new_default_langcode = $saved_config->get('default_langcode');
         $default_language = $this->configFactory->get('language.entity.' . $new_default_langcode);
         // During an import the language might not exist yet.
         if (!$default_language->isNew()) {
             $this->languageDefault->set(new Language($default_language->get()));
             $this->languageManager->reset();
             // Directly update language negotiation settings instead of calling
             // language_negotiation_url_prefixes_update() to ensure that the code
             // obeys the hook_update_N() restrictions.
             $negotiation_config = $this->configFactory->getEditable('language.negotiation');
             $negotiation_changed = FALSE;
             $url_prefixes = $negotiation_config->get('url.prefixes');
             $old_default_langcode = $saved_config->getOriginal('default_langcode');
             if (empty($url_prefixes[$old_default_langcode])) {
                 $negotiation_config->set('url.prefixes.' . $old_default_langcode, $old_default_langcode);
                 $negotiation_changed = TRUE;
             }
             if (empty($url_prefixes[$new_default_langcode])) {
                 $negotiation_config->set('url.prefixes.' . $new_default_langcode, '');
                 $negotiation_changed = TRUE;
             }
             if ($negotiation_changed) {
                 $negotiation_config->save(TRUE);
             }
         }
         // Trigger a container rebuild on the next request by invalidating it.
         ConfigurableLanguageManager::rebuildServices();
     }
 }
 /**
  * Causes the container to be rebuilt on the next request.
  *
  * @param ConfigCrudEvent $event
  *   The configuration event.
  */
 public function onConfigSave(ConfigCrudEvent $event)
 {
     $saved_config = $event->getConfig();
     if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) {
         $language = $this->languageManager->getLanguage($saved_config->get('default_langcode'));
         // During an import the language might not exist yet.
         if ($language) {
             $this->languageDefault->set($language);
             $this->languageManager->reset();
             language_negotiation_url_prefixes_update();
         }
         // Trigger a container rebuild on the next request by invalidating it.
         ConfigurableLanguageManager::rebuildServices();
     }
 }
 /**
  * Causes the container to be rebuilt on the next request.
  *
  * @param ConfigCrudEvent $event
  *   The configuration event.
  */
 public function onConfigSave(ConfigCrudEvent $event)
 {
     $saved_config = $event->getConfig();
     if ($saved_config->getName() == 'system.site' && $event->isChanged('langcode')) {
         $language = $this->languageManager->getLanguage($saved_config->get('langcode'));
         // During an import the language might not exist yet.
         if ($language) {
             $this->languageDefault->set($language);
             $this->languageManager->reset();
             language_negotiation_url_prefixes_update();
         }
         // Trigger a container rebuild on the next request by deleting compiled
         // from PHP storage.
         PhpStorageFactory::get('service_container')->deleteAll();
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultLanguage()
 {
     return $this->defaultLanguage->get();
 }
 /**
  * {@inheritdoc}
  */
 public function setLanguageFromDefault(LanguageDefault $language_default = NULL)
 {
     $this->language = $language_default ? $language_default->get() : NULL;
     return $this;
 }
Esempio n. 6
0
 /**
  * Constructs a TranslationManager object.
  *
  * @param \Drupal\Core\Language\LanguageDefault $default_language
  *   The default language.
  */
 public function __construct(LanguageDefault $default_language)
 {
     $this->defaultLangcode = $default_language->get()->getId();
 }