function PathProcessorLanguage::initProcessors

Same name in other branches
  1. 9 core/modules/language/src/HttpKernel/PathProcessorLanguage.php \Drupal\language\HttpKernel\PathProcessorLanguage::initProcessors()
  2. 8.9.x core/modules/language/src/HttpKernel/PathProcessorLanguage.php \Drupal\language\HttpKernel\PathProcessorLanguage::initProcessors()
  3. 11.x core/modules/language/src/HttpKernel/PathProcessorLanguage.php \Drupal\language\HttpKernel\PathProcessorLanguage::initProcessors()

Initializes the local cache for language path processors.

Parameters

string $scope: The scope of the processors: "inbound" or "outbound".

2 calls to PathProcessorLanguage::initProcessors()
PathProcessorLanguage::processInbound in core/modules/language/src/HttpKernel/PathProcessorLanguage.php
PathProcessorLanguage::processOutbound in core/modules/language/src/HttpKernel/PathProcessorLanguage.php

File

core/modules/language/src/HttpKernel/PathProcessorLanguage.php, line 131

Class

PathProcessorLanguage
Processes the inbound path using path alias lookups.

Namespace

Drupal\language\HttpKernel

Code

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])) {
                if (is_subclass_of($method['class'], $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) {
        return $weights[$method_id_a] <=> $weights[$method_id_b];
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.