public function LanguageNegotiator::updateConfiguration in Drupal 10
Same name and namespace in other branches
- 8 core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::updateConfiguration()
- 9 core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::updateConfiguration()
File
- core/modules/language/src/LanguageNegotiator.php, line 297
Class
- LanguageNegotiator
- Class responsible for performing language negotiation.
Namespace
Drupal\language
Code
public function updateConfiguration(array $types) {
$this->negotiatorManager
->clearCachedDefinitions();
$this->languageManager
->reset();
$language_types = [];
$language_types_info = $this->languageManager
->getDefinedLanguageTypesInfo();
$method_definitions = $this
->getNegotiationMethods();
foreach ($language_types_info as $type => $info) {
$configurable = in_array($type, $types);
$has_default_settings = !empty($info['fixed']);
if (empty($info['locked'])) {
if (!$configurable && !$has_default_settings) {
$method_weights = [
LanguageNegotiationUI::METHOD_ID,
];
$method_weights = array_flip($method_weights);
$this
->saveConfiguration($type, $method_weights);
}
}
else {
if ($has_default_settings) {
$method_weights = [];
foreach ($info['fixed'] as $weight => $method_id) {
if (isset($method_definitions[$method_id])) {
$method_weights[$method_id] = $weight;
}
}
$this
->saveConfiguration($type, $method_weights);
}
else {
$configurable = TRUE;
}
}
$language_types[$type] = $configurable;
}
$config = [
'configurable' => array_keys(array_filter($language_types)),
'all' => array_keys($language_types),
];
$this->languageManager
->saveLanguageTypesConfiguration($config);
}