function LanguageNegotiator::saveConfiguration
Same name in other branches
- 9 core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::saveConfiguration()
- 8.9.x core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::saveConfiguration()
- 11.x core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::saveConfiguration()
2 calls to LanguageNegotiator::saveConfiguration()
- LanguageNegotiator::purgeConfiguration in core/
modules/ language/ src/ LanguageNegotiator.php - LanguageNegotiator::updateConfiguration in core/
modules/ language/ src/ LanguageNegotiator.php
File
-
core/
modules/ language/ src/ LanguageNegotiator.php, line 259
Class
- LanguageNegotiator
- Class responsible for performing language negotiation.
Namespace
Drupal\languageCode
public function saveConfiguration($type, $enabled_methods) {
// As configurable language types might have changed, we reset the cache.
$this->languageManager
->reset();
$definitions = $this->getNegotiationMethods();
$default_types = $this->languageManager
->getLanguageTypes();
// Ensure that the weights are integers.
$enabled_methods = array_map('intval', $enabled_methods);
// Order the language negotiation method list by weight.
asort($enabled_methods);
foreach ($enabled_methods as $method_id => $weight) {
if (isset($definitions[$method_id])) {
$method = $definitions[$method_id];
// If the language negotiation method does not express any preference
// about types, make it available for any configurable type.
$types = array_flip(!empty($method['types']) ? $method['types'] : $default_types);
// Check whether the method is defined and has the right type.
if (!isset($types[$type])) {
unset($enabled_methods[$method_id]);
}
}
else {
unset($enabled_methods[$method_id]);
}
}
$this->configFactory
->getEditable('language.types')
->set('negotiation.' . $type . '.enabled', $enabled_methods)
->save(TRUE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.