Issue #3358402 by totten, lisotton, jensschuppe, larowlan, znerol: [regression] route defaults are now automatically route parameters
(cherry picked from commit 75d3d2d11f
)
merge-requests/4156/head
parent
1991a7b670
commit
9f71d94aaa
|
@ -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')) {
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue