Commit 877e4a81 authored by alexpott's avatar alexpott

Issue #2462729 by segi, Yogesh Pawar, andypost, rpayanm, Gábor Hojtsy,...

Issue #2462729 by segi, Yogesh Pawar, andypost, rpayanm, Gábor Hojtsy, alexpott, sidharthap, tstoeckler, tim.plunkett: Move ConfigurableLanguage hook implementations in language module to the entity
parent d85463b0
......@@ -15,7 +15,6 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
......@@ -346,38 +345,6 @@ function language_modules_uninstalled($modules) {
language_modules_installed($modules);
}
/**
* Implements hook_ENTITY_TYPE_insert() for 'configurable_language'.
*/
function language_configurable_language_insert(ConfigurableLanguageInterface $language) {
if ($language->isLocked()) {
return;
}
// Add language to the list of language domains.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$domains = $config->get('url.domains');
$domains[$language->id()] = '';
$config->set('url.domains', $domains)->save();
}
/**
* Implements hook_ENTITY_TYPE_delete() for 'configurable_language'.
*/
function language_configurable_language_delete(ConfigurableLanguageInterface $language) {
// Remove language from language prefix list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$prefixes = $config->get('url.prefixes');
unset($prefixes[$language->id()]);
$config->set('url.prefixes', $prefixes)->save();
// Remove language from language domain list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$domains = $config->get('url.domains');
unset($domains[$language->id()]);
$config->set('url.domains', $domains)->save();
}
/**
* Implements hook_preprocess_HOOK() for block templates.
*/
......
......@@ -139,6 +139,14 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// 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();
}
}
/**
......@@ -173,6 +181,12 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
if (!\Drupal::languageManager()->isMultilingual()) {
ConfigurableLanguageManager::rebuildServices();
}
// Remove language from language prefix and domain list.
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$config->clear('url.prefixes.' . $entity->id());
$config->clear('url.domains.' . $entity->id());
$config->save();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment