You are here

function LanguageNegotiator::saveConfiguration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::saveConfiguration()

Saves a list of language negotiation methods for a language type.

Parameters

string $type: The language type.

int[] $enabled_methods: An array of language negotiation method weights keyed by method ID.

Overrides LanguageNegotiatorInterface::saveConfiguration

2 calls to LanguageNegotiator::saveConfiguration()
LanguageNegotiator::purgeConfiguration in core/modules/language/src/LanguageNegotiator.php
Resave the configuration to purge missing negotiation methods.
LanguageNegotiator::updateConfiguration in core/modules/language/src/LanguageNegotiator.php
Updates the configuration based on the given language types.

File

core/modules/language/src/LanguageNegotiator.php, line 253
Contains \Drupal\language\LanguageNegotiator.

Class

LanguageNegotiator
Class responsible for performing language negotiation.

Namespace

Drupal\language

Code

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();

  // 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();
}