From 7a8e01b9b9ebceb4d474e23104ada9b0a5555a1f Mon Sep 17 00:00:00 2001 From: kristiaanvandeneynde Date: Wed, 27 Oct 2021 14:41:18 +0500 Subject: [PATCH] Issue #3245953 by kristiaanvandeneynde: TwigExtension::drupalTitle() should check for NullRouteMatch --- src/TwigTweakExtension.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index d62a343..ea04e2e 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -314,12 +314,14 @@ class TwigTweakExtension extends AbstractExtension { /** * Returns a title for the current route. + * + * @todo Test it with NullRouteMatch */ public static function drupalTitle(): array { - $title = \Drupal::service('title_resolver')->getTitle( - \Drupal::request(), - \Drupal::routeMatch()->getRouteObject() - ); + $title = NULL; + if ($route = \Drupal::routeMatch()->getRouteObject()) { + $title = \Drupal::service('title_resolver')->getTitle(\Drupal::request(), $route); + } $build['#markup'] = render($title); $build['#cache']['contexts'] = ['url']; return $build;