Skip to content
Snippets Groups Projects
Commit c1c27f3c authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2576945 by hchonov: PathProcessorLanguage::initProcessors is not...

Issue #2576945 by hchonov: PathProcessorLanguage::initProcessors is not sorting the methods by weight
parent a52618e5
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -125,16 +125,31 @@ public function processOutbound($path, &$options = array(), Request $request = N
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;
});
}
}
......@@ -62,6 +62,7 @@ protected function setUp() {
$method_definitions = array(
LanguageNegotiationUrl::METHOD_ID => array(
'class' => '\Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl',
'weight' => 9,
),
);
......@@ -134,7 +135,10 @@ function testProcessInbound() {
->getMock();
$negotiator->expects($this->any())
->method('getNegotiationMethods')
->will($this->returnValue(array(LanguageNegotiationUrl::METHOD_ID => array('class' => 'Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl'))));
->will($this->returnValue(array(LanguageNegotiationUrl::METHOD_ID => array(
'class' => 'Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl',
'weight' => 9,
))));
$method = new LanguageNegotiationUrl();
$method->setConfig($config_factory_stub);
$method->setLanguageManager($this->languageManager);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment