diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index 2cf06eca7e4acbdd578dee00e3a521f5b4bb8e21..cab95d27bad23c5e75da644c17b7569304c1da42 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -57,10 +57,11 @@ public function getTitle(Request $request, Route $route) { $arguments = $this->argumentResolver->getArguments($request, $callable); $route_title = call_user_func_array($callable, $arguments); } - elseif ($title = $route->getDefault('_title')) { + elseif ($route->hasDefault('_title') && strlen($route->getDefault('_title')) > 0) { + $title = $route->getDefault('_title'); $options = []; - if ($context = $route->getDefault('_title_context')) { - $options['context'] = $context; + if ($route->hasDefault('_title_context')) { + $options['context'] = $route->getDefault('_title_context'); } $args = []; if (($raw_parameters = $request->attributes->get('_raw_variables'))) { diff --git a/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php index 2eb2e20de1a950a3fc6c031a27d404eb11f15f8e..76e6e87188adaaa1f2769cd29e272f0f1d97620c 100644 --- a/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php @@ -70,6 +70,17 @@ public function testStaticTitle() { $this->assertEquals(new TranslatableMarkup('static title', [], [], $this->translationManager), $this->titleResolver->getTitle($request, $route)); } + /** + * Tests a static title of '0'. + * + * @see \Drupal\Core\Controller\TitleResolver::getTitle() + */ + public function testStaticTitleZero() { + $request = new Request(); + $route = new Route('/test-route', ['_title' => '0', '_title_context' => '0']); + $this->assertEquals(new TranslatableMarkup('0', [], ['context' => '0'], $this->translationManager), $this->titleResolver->getTitle($request, $route)); + } + /** * Tests a static title with a context. *