Ejemplo n.º 1
0
 /**
  * Initializes the local cache for language path processors.
  *
  * @param string $scope
  *   The scope of the processors: "inbound" or "outbound".
  */
 protected function initProcessors($scope)
 {
     $interface = '\\Drupal\\Core\\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
     $this->processors[$scope] = array();
     $weights = [];
     foreach ($this->languageManager->getLanguageTypes() as $type) {
         foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
             if (!isset($this->processors[$scope][$method_id])) {
                 $reflector = new \ReflectionClass($method['class']);
                 if ($reflector->implementsInterface($interface)) {
                     $this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
                     $weights[$method_id] = $method['weight'];
                 }
             }
         }
     }
     // Sort the processors list, so that their functions are called in the
     // order specified by the weight of the methods.
     uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use($weights) {
         $a_weight = $weights[$method_id_a];
         $b_weight = $weights[$method_id_b];
         if ($a_weight == $b_weight) {
             return 0;
         }
         return $a_weight < $b_weight ? -1 : 1;
     });
 }
 /**
  * Initializes the local cache for language path processors.
  *
  * @param string $scope
  *   The scope of the processors: "inbound" or "outbound".
  */
 protected function initProcessors($scope)
 {
     $interface = '\\Drupal\\Core\\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
     $this->processors[$scope] = array();
     foreach ($this->languageManager->getLanguageTypes() as $type) {
         foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
             if (!isset($this->processors[$scope][$method_id])) {
                 $reflector = new \ReflectionClass($method['class']);
                 if ($reflector->implementsInterface($interface)) {
                     $this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 function saveConfiguration($type, $enabled_methods)
 {
     $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->get('language.types')->set('negotiation.' . $type . '.enabled', $enabled_methods)->save();
 }