diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index 6bd0cd0..5a1ca50 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -69,6 +69,10 @@ public function getTitle(Request $request, Route $route) { $args['%' . $key] = $value; } } + if ($title_arguments = $route->getDefault('_title_arguments')) { + $args = array_merge($args, (array) $title_arguments); + } + // Fall back to a static string from the route. $route_title = $this->translationManager->translate($title, $args, $options); } diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php b/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php index 96f2d32..2139735 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php @@ -31,6 +31,10 @@ public function getTitle(Request $request = NULL) { $args['!' . $key] = $value; } } + if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) { + $args = array_merge($args, (array) $title_arguments); + } + return $this->t($this->pluginDefinition['title'], $args, $options); } diff --git a/core/lib/Drupal/Core/Menu/LocalActionDefault.php b/core/lib/Drupal/Core/Menu/LocalActionDefault.php index e3fa639..4b12850 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalActionDefault.php @@ -79,6 +79,9 @@ public function getTitle(Request $request = NULL) { $args['!' . $key] = $value; } } + if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) { + $args = array_merge($args, (array) $title_arguments); + } return $this->t($this->pluginDefinition['title'], $args, $options); } diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index 26671b3..eba1df9 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -87,6 +87,9 @@ public function getTitle(Request $request = NULL) { $args['!' . $key] = $value; } } + if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) { + $args = array_merge($args, (array) $title_arguments); + } return $this->t($this->pluginDefinition['title'], $args, $options); } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php index a165509..83732f1 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php @@ -127,6 +127,22 @@ public function testGetTitleWithParameter() { } /** + * Tests the getTitle method with title arguments. + */ + public function testGetTitleWithTitleArguments() { + $this->pluginDefinition['title'] = 'Example @test'; + $this->pluginDefinition['title_arguments'] = array('@test' => 'value'); + $this->stringTranslation->expects($this->once()) + ->method('translate') + ->with($this->pluginDefinition['title'], $this->arrayHasKey('@test'), array()) + ->will($this->returnValue('Example value')); + + $this->setupContextualLinkDefault(); + $request = new Request(); + $this->assertEquals('Example value', $this->contextualLinkDefault->getTitle($request)); + } + + /** * Tests the getRouteName() method. * * @covers \Drupal\Core\Menu\ContextualLinkDefault::getRouteName() diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php index 682848e..a29ac6b 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php @@ -136,4 +136,20 @@ public function testGetTitleWithParameter() { $this->assertEquals('Example value', $this->localActionDefault->getTitle($request)); } + /** + * Tests the getTitle method with title arguments. + */ + public function testGetTitleWithTitleArguments() { + $this->pluginDefinition['title'] = 'Example @test'; + $this->pluginDefinition['title_arguments'] = array('@test' => 'value'); + $this->stringTranslation->expects($this->once()) + ->method('translate') + ->with($this->pluginDefinition['title'], $this->arrayHasKey('@test'), array()) + ->will($this->returnValue('Example value')); + + $this->setupLocalActionDefault(); + $request = new Request(); + $this->assertEquals('Example value', $this->localActionDefault->getTitle($request)); + } + } diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index f1cf965..e4c4c1f 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -306,6 +306,22 @@ public function testGetTitleWithParameter() { } /** + * Tests the getTitle method with title arguments. + */ + public function testGetTitleWithTitleArguments() { + $this->pluginDefinition['title'] = 'Example @test'; + $this->pluginDefinition['title_arguments'] = array('@test' => 'value'); + $this->stringTranslation->expects($this->once()) + ->method('translate') + ->with($this->pluginDefinition['title'], $this->arrayHasKey('@test'), array()) + ->will($this->returnValue('Example value')); + + $this->setupLocalTaskDefault(); + $request = new Request(); + $this->assertEquals('Example value', $this->localTaskBase->getTitle($request)); + } + + /** * Tests the getOption method. * * @see \Drupal\Core\Menu\LocalTaskDefault::getOption()