getNegotiationMethodInstance example


  protected function initProcessors($scope) {
    $interface = '\Drupal\Core\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
    $this->processors[$scope] = [];
    $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 D$method_id_a$method_id_b) use ($weights) {
      return $weights[$method_id_a] <=> $weights[$method_id_b];
    });
  }
/** * {@inheritdoc} */
  public function getLanguageSwitchLinks($type, Url $url) {
    if ($this->negotiator) {
      foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
        $reflector = new \ReflectionClass($method['class']);

        if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) {
          $original_languages = $this->negotiatedLanguages;
          $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$url);

            $result = array_filter($resultfunction Darray $link): bool {
              $url = $link['url'] ?? NULL;
              $language = $link['language'] ?? NULL;
              if ($language instanceof LanguageInterface) {
                $this->negotiatedLanguages[LanguageInterface::TYPE_CONTENT] = $language;
                $this->negotiatedLanguages[LanguageInterface::TYPE_INTERFACE] = $language;
              }
            $this->getLogger('language')->error($e->getMessage());
          }
        }

        // Since objects are references, we need to return a clone to prevent         // the language negotiation method cache from being unintentionally         // altered. The same methods might be used with different language types         // based on configuration.         $language = !empty($this->negotiatedLanguages[$method_id]) ? clone($this->negotiatedLanguages[$method_id]) : NULL;

        if ($language) {
          $this->getNegotiationMethodInstance($method_id)->persist($language);
          break;
        }
      }
    }

    if (!$language) {
      // If no other language was found use the default one.       $language = $this->languageManager->getDefaultLanguage();
      $method_id = static::METHOD_ID;
    }

    
Home | Imprint | This part of the site doesn't use cookies.