diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index cab95d27bad..82c068113c3 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -66,8 +66,10 @@ class TitleResolver implements TitleResolverInterface { $args = []; if (($raw_parameters = $request->attributes->get('_raw_variables'))) { foreach ($raw_parameters->all() as $key => $value) { - $args['@' . $key] = $value ?? ''; - $args['%' . $key] = $value ?? ''; + if (is_scalar($value)) { + $args['@' . $key] = $value; + $args['%' . $key] = $value; + } } } if ($title_arguments = $route->getDefault('_title_arguments')) { diff --git a/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php index 76e6e87188a..945503f543c 100644 --- a/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php @@ -117,21 +117,24 @@ class TitleResolverTest extends UnitTestCase { } /** - * Tests a static title with a NULL value parameter. + * Tests a static title with a non-scalar value parameter. * * @see \Drupal\Core\Controller\TitleResolver::getTitle() */ - public function testStaticTitleWithNullValueParameter() { - $raw_variables = new InputBag(['test' => NULL, 'test2' => 'value']); + public function testStaticTitleWithNullAndArrayValueParameter() { + $raw_variables = new InputBag(['test1' => NULL, 'test2' => ['foo' => 'bar'], 'test3' => 'value']); $request = new Request(); $request->attributes->set('_raw_variables', $raw_variables); - $route = new Route('/test-route', ['_title' => 'static title %test @test']); + $route = new Route('/test-route', ['_title' => 'static title %test1 @test1 %test2 @test2 %test3 @test3']); $translatable_markup = $this->titleResolver->getTitle($request, $route); - $this->assertSame('', $translatable_markup->getArguments()['@test']); - $this->assertSame('', $translatable_markup->getArguments()['%test']); - $this->assertSame('value', $translatable_markup->getArguments()['@test2']); - $this->assertSame('value', $translatable_markup->getArguments()['%test2']); + $arguments = $translatable_markup->getArguments(); + $this->assertNotContains('@test1', $arguments); + $this->assertNotContains('%test1', $arguments); + $this->assertNotContains('@test2', $arguments); + $this->assertNotContains('%test2', $arguments); + $this->assertSame('value', $translatable_markup->getArguments()['@test3']); + $this->assertSame('value', $translatable_markup->getArguments()['%test3']); } /**