diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php index 295c904..67c9d0c 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManager.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php @@ -67,7 +67,7 @@ class AuthenticationManager implements AuthenticationProviderInterface, Authenti /** * {@inheritdoc} */ - public function addProvider(AuthenticationProviderInterface $provider, $priority = 0, $provider_id, $global = FALSE) { + public function addProvider(AuthenticationProviderInterface $provider, $provider_id, $priority = 0, $global = FALSE) { $this->providers[$provider_id] = $provider; $this->providerOrders[$priority][$provider_id] = $provider; // Force the builders to be re-sorted. diff --git a/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php b/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php index 032e840..8477fc3 100644 --- a/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManagerInterface.php @@ -20,10 +20,11 @@ * @param string $provider_id * Identifier of the provider. * @param int $priority - * The providers priority. + * (optional) The provider's priority. * @param bool $global - * TRUE if the provider is to be applied globally on all routes. + * (optional) TRUE if the provider is to be applied globally on all routes. + * Defaults to FALSE. */ - public function addProvider(AuthenticationProviderInterface $provider, $priority = 0, $provider_id, $global = FALSE); + public function addProvider(AuthenticationProviderInterface $provider, $provider_id, $priority = 0, $global = FALSE); } diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php index f06b0ac..eee92e6 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php @@ -155,11 +155,19 @@ public function process(ContainerBuilder $container) { if (isset($id_pos)) { $arguments[$id_pos] = $id; } - // Sort the arguments by position. - ksort($arguments); + // Add in extra arguments. if (isset($extra_arguments[$id])) { - $arguments += $extra_arguments[$id]; + // Don't overwrite the primary arguments. + unset($extra_arguments[$id][$interface_pos]); + unset($extra_arguments[$id][$priority_pos]); + unset($extra_arguments[$id][$id_pos]); + // Place extra arguments in their right positions. + foreach ($extra_arguments[$id] as $pos => $argument) { + $arguments[$pos] = $argument; + } } + // Sort the arguments by position. + ksort($arguments); $consumer->addMethodCall($method_name, $arguments); } } diff --git a/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php b/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php index eb40ef7..da7331d 100644 --- a/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php @@ -30,7 +30,7 @@ class AuthenticationManagerTest extends UnitTestCase { public function testDefaultFilter($applies, $has_route, $auth_option, $provider_id, $global) { $authentication_manager = new AuthenticationManager(); $auth_provider = $this->getMock('Drupal\Core\Authentication\AuthenticationProviderInterface'); - $authentication_manager->addProvider($auth_provider, 0, $provider_id, $global); + $authentication_manager->addProvider($auth_provider, $provider_id, 0, $global); $request = new Request(); if ($has_route) { @@ -50,7 +50,7 @@ public function testDefaultFilter($applies, $has_route, $auth_option, $provider_ public function testApplyFilterWithFilterprovider() { $authentication_manager = new AuthenticationManager(); $auth_provider = $this->getMock('Drupal\Tests\Core\Authentication\TestAuthenticationProviderInterface'); - $authentication_manager->addProvider($auth_provider, 0, 'filtered'); + $authentication_manager->addProvider($auth_provider, 'filtered', 0); $auth_provider->expects($this->once()) ->method('appliesToRoutedRequest') diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index b3948fa..86a1c9c 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -317,6 +317,37 @@ public function testProcessWithIdAndExtraArguments() { $this->assertNull($method_calls[0][1][4]); } + /** + * Tests consumer method with priority and extra parameters in different order. + * + * @covers ::process + */ + public function testProcessWithDifferentArgumentsOrder() { + $container = $this->buildContainer(); + + $container + ->register('consumer_id', __NAMESPACE__ . '\ValidConsumerWithExtraArguments') + ->addTag('service_collector', array( + 'call' => 'addWithDifferentOrder' + )); + + $container + ->register('handler1', __NAMESPACE__ . '\ValidHandler') + ->addTag('consumer_id', array( + 'priority' => 0, + 'extra1' => 'extra1', + 'extra2' => 'extra2', + )); + + $handler_pass = new TaggedHandlersPass(); + $handler_pass->process($container); + + $method_calls = $container->getDefinition('consumer_id')->getMethodCalls(); + $this->assertCount(4, $method_calls[0][1]); + $expected = [new Reference('handler1'), 'extra1', 0, 'extra2']; + $this->assertEquals($expected, array_values($method_calls[0][1])); + } + } interface HandlerInterface { @@ -340,6 +371,8 @@ public function addNoPriority(HandlerInterface $instance, $extra) { } public function addWithId(HandlerInterface $instance, $id, $priority = 0, $extra1, $extra2) { } + public function addWithDifferentOrder(HandlerInterface $instance, $extra1, $priority = 0, $extra2) { + } } class ValidHandler implements HandlerInterface { }