diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index a418661..5b9103a 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -44,29 +44,31 @@ public function __construct(ControllerResolverInterface $controller_resolver, Tr } /** - * Returns the title from a static or dynamic title. + * Returns the title from a static or dynamic title for the route. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object passed to the title callback. * @param \Symfony\Component\Routing\Route $route * The route information of the route to fetch the title. * - * @return string - * The title of the route as string. + * @return string|NULL + * The title for the route. */ public function getTitle(Request $request, Route $route) { - // A dynamic title takes priority. - if ($route->hasDefault('_title_callback')) { - $callback = $route->getDefault('_title_callback'); + $route_title = NULL; + // A dynamic title takes priority. Route::getDefault() returns NULL if the + // named default is not set. By testing thevalue directly, we also + // avoid trying to use empty values. + if ($callback = $route->getDefault('_title_callback')) { $callable = $this->controllerResolver->getControllerFromDefinition($callback); $arguments = $this->controllerResolver->getArguments($request, $callable); - return call_user_func_array($callable, $arguments); + $route_title = call_user_func_array($callable, $arguments); } - elseif ($route->hasDefault('_title')) { + elseif ($title = $route->getDefault('_title')) { // Fall back to a static string from the route. - $title = $route->getDefault('_title'); - return $this->t($title); + $route_title = $this->t($title); } + return $route_title; } /**