/**
  * 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);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $configurable = $this->languageTypes->get('configurable');
     $form = array('#theme' => 'language_negotiation_configure_form', '#language_types_info' => $this->languageManager->getDefinedLanguageTypesInfo(), '#language_negotiation_info' => $this->negotiator->getNegotiationMethods());
     $form['#language_types'] = array();
     foreach ($form['#language_types_info'] as $type => $info) {
         // Show locked language types only if they are configurable.
         if (empty($info['locked']) || in_array($type, $configurable)) {
             $form['#language_types'][] = $type;
         }
     }
     foreach ($form['#language_types'] as $type) {
         $this->configureFormTable($form, $type);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Save settings'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function getLanguageSwitchLinks($type, Url $url)
 {
     $links = FALSE;
     if ($this->negotiator) {
         foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
             $reflector = new \ReflectionClass($method['class']);
             if ($reflector->implementsInterface('\\Drupal\\language\\LanguageSwitcherInterface')) {
                 $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url);
                 if (!empty($result)) {
                     // Allow modules to provide translations for specific links.
                     $this->moduleHandler->alter('language_switch_links', $result, $type, $path);
                     $links = (object) array('links' => $result, 'method_id' => $method_id);
                     break;
                 }
             }
         }
     }
     return $links;
 }