From 1ab5db0352fa1b8ef99c582677b8292f334db219 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 2 Mar 2023 11:00:50 +0000 Subject: [PATCH] Issue #3344744 by alexpott: A route with a default title of 0 does not work --- core/lib/Drupal/Core/Controller/TitleResolver.php | 7 ++++--- .../Tests/Core/Controller/TitleResolverTest.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index 2cf06eca7e4a..cab95d27bad2 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 2eb2e20de1a9..76e6e87188ad 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. * -- GitLab