diff --git a/core/core.services.yml b/core/core.services.yml index 3e3b9ca..a44ebb3 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -403,7 +403,7 @@ services: paramconverter_manager: class: Drupal\Core\ParamConverter\ParamConverterManager tags: - - { name: service_collector, tag: paramconverter, call: ParamConverterManager } + - { name: service_collector, tag: paramconverter, call: addConverter } paramconverter_subscriber: class: Drupal\Core\EventSubscriber\ParamConverterSubscriber tags: diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php index 78f21f9..43e10ef 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php @@ -86,6 +86,9 @@ public function process(ContainerBuilder $container) { $method = new \ReflectionMethod($consumer->getClass(), $method_name); $params = $method->getParameters(); + $interface_pos = NULL; + $id_pos = NULL; + $priority_pos = NULL; foreach ($params as $pos => $param) { if ($param->getClass()) { $interface_pos = $pos; @@ -142,6 +145,8 @@ public function process(ContainerBuilder $container) { if (isset($id_pos)) { $arguments[$id_pos] = $id; } + // Sort the arguments by position. + ksort($arguments); $consumer->addMethodCall($method_name, $arguments); } } diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php index 887ca6e..69d2b05 100644 --- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php +++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php @@ -47,26 +47,6 @@ public function setUp() { } /** - * Tests \Drupal\Core\ParamConverter\ParamConverterManager::addConverter(). - * - * @dataProvider providerTestAddConverter - * - * @covers ::addConverter() - * @covers ::getConverterIds() - */ - public function testAddConverter($unsorted, $sorted) { - foreach ($unsorted as $data) { - $this->manager->addConverter($data['name'], $data['priority']); - } - - // Test that ResolverManager::getTypedDataResolvers() returns the resolvers - // in the expected order. - foreach ($this->manager->getConverterIds() as $key => $converter) { - $this->assertEquals($sorted[$key], $converter); - } - } - - /** * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter(). * * @dataProvider providerTestGetConverter @@ -78,11 +58,7 @@ public function testGetConverter($name, $priority, $class) { ->setMockClassName($class) ->getMock(); - $this->manager->addConverter($name, $priority); - $this->container->expects($this->once()) - ->method('get') - ->with($name) - ->will($this->returnValue($converter)); + $this->manager->addConverter($name, $converter, $priority); $this->assertInstanceOf($class, $this->manager->getConverter($name)); // Assert that a second call to getConverter() does not use the container. @@ -175,11 +151,7 @@ public function testSetRouteParameterConverters($path, $parameters = NULL, $expe ->method('applies') ->with($this->anything(), 'id', $this->anything()) ->will($this->returnValue(TRUE)); - $this->manager->addConverter('applied'); - $this->container->expects($this->any()) - ->method('get') - ->with('applied') - ->will($this->returnValue($converter)); + $this->manager->addConverter('applied', $converter); $route = new Route($path); if ($parameters) { @@ -241,11 +213,7 @@ public function testConvert() { ->method('convert') ->with(1, $this->isType('array'), 'id', $this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request')) ->will($this->returnValue('something_better!')); - $this->manager->addConverter('test_convert'); - $this->container->expects($this->once()) - ->method('get') - ->with('test_convert') - ->will($this->returnValue($converter)); + $this->manager->addConverter('test_convert', $converter); $result = $this->manager->convert($defaults, new Request()); @@ -294,11 +262,7 @@ public function testConvertMissingParam() { ->method('convert') ->with(1, $this->isType('array'), 'id', $this->isType('array'), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request')) ->will($this->returnValue(NULL)); - $this->manager->addConverter('test_convert'); - $this->container->expects($this->once()) - ->method('get') - ->with('test_convert') - ->will($this->returnValue($converter)); + $this->manager->addConverter('test_convert', $converter); $this->manager->convert($defaults, new Request()); }