diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php index 0ca34d6..aad1dcd 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/TaggedHandlersPass.php @@ -99,7 +99,7 @@ public function process(ContainerBuilder $container) { if ($param->getClass()) { $interface = $param->getClass(); } - if ($param->getName() === 'id') { + else if ($param->getName() === 'id') { $id_pos = $pos; } else if ($param->getName() === 'priority') { @@ -132,7 +132,7 @@ public function process(ContainerBuilder $container) { $handlers[$id] = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; // Keep track of other tagged handlers arguments. foreach ($extra_params as $name => $pos) { - $extra_arguments[$id][$pos] = isset($attributes[0][$name]) ? $attributes[0][$name] : NULL; + $extra_arguments[$id][$pos] = isset($attributes[0][$name]) ? $attributes[0][$name] : $params[$pos]->getDefaultValue(); } } if (empty($handlers)) { diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php index 86a1c9c..055a907 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php @@ -322,7 +322,7 @@ public function testProcessWithIdAndExtraArguments() { * * @covers ::process */ - public function testProcessWithDifferentArgumentsOrder() { + public function testProcessWithDifferentArgumentsOrderAndDefaultValue() { $container = $this->buildContainer(); $container @@ -336,15 +336,15 @@ public function testProcessWithDifferentArgumentsOrder() { ->addTag('consumer_id', array( 'priority' => 0, 'extra1' => 'extra1', - 'extra2' => 'extra2', + 'extra3' => 'extra3' )); $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->assertCount(5, $method_calls[0][1]); + $expected = [new Reference('handler1'), 'extra1', 0, 'default2', 'extra3']; $this->assertEquals($expected, array_values($method_calls[0][1])); } @@ -365,13 +365,13 @@ public function addHandler($instance, $priority = 0) { } } class ValidConsumerWithExtraArguments { - public function addHandler(HandlerInterface $instance, $priority = 0, $extra1, $extra2) { + public function addHandler(HandlerInterface $instance, $priority = 0, $extra1 = '', $extra2 = '') { } public function addNoPriority(HandlerInterface $instance, $extra) { } - public function addWithId(HandlerInterface $instance, $id, $priority = 0, $extra1, $extra2) { + public function addWithId(HandlerInterface $instance, $id, $priority = 0, $extra1 = '', $extra2 = NULL) { } - public function addWithDifferentOrder(HandlerInterface $instance, $extra1, $priority = 0, $extra2) { + public function addWithDifferentOrder(HandlerInterface $instance, $extra1, $priority = 0, $extra2 = 'default2', $extra3 = 'default3') { } } class ValidHandler implements HandlerInterface {