From f70c2b289dc80d7a14008a9a37804590c8a0c7cc Mon Sep 17 00:00:00 2001 From: core23 Date: Fri, 1 May 2020 13:54:26 +0200 Subject: [PATCH] Catch possible null error when retriving site --- src/Block/ChildrenPagesBlockService.php | 7 +++++-- src/Route/CmsPageRouter.php | 5 +++++ src/Site/BaseSiteSelector.php | 2 +- src/Site/SiteSelectorInterface.php | 2 +- src/Twig/Extension/PageExtension.php | 10 +++++++--- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Block/ChildrenPagesBlockService.php b/src/Block/ChildrenPagesBlockService.php index f8c3ae17b..74d67347b 100755 --- a/src/Block/ChildrenPagesBlockService.php +++ b/src/Block/ChildrenPagesBlockService.php @@ -67,10 +67,13 @@ public function execute(BlockContextInterface $blockContext, ?Response $response } elseif ($settings['pageId']) { $page = $settings['pageId']; } else { + $page = false; try { - $page = $cmsManager->getPage($this->siteSelector->retrieve(), '/'); + $site = $this->siteSelector->retrieve(); + if (null !== $site) { + $page = $cmsManager->getPage($site, '/'); + } } catch (PageNotFoundException $e) { - $page = false; } } diff --git a/src/Route/CmsPageRouter.php b/src/Route/CmsPageRouter.php index 905ab55e7..871d17ac2 100644 --- a/src/Route/CmsPageRouter.php +++ b/src/Route/CmsPageRouter.php @@ -302,6 +302,11 @@ protected function getRelativePath($basePath, $targetPath) protected function getPageByPageAlias($alias) { $site = $this->siteSelector->retrieve(); + + if (null === $site) { + return null; + } + $page = $this->cmsSelector->retrieve()->getPageByPageAlias($site, $alias); return $page; diff --git a/src/Site/BaseSiteSelector.php b/src/Site/BaseSiteSelector.php index 4c92e9563..fa3151be2 100644 --- a/src/Site/BaseSiteSelector.php +++ b/src/Site/BaseSiteSelector.php @@ -44,7 +44,7 @@ abstract class BaseSiteSelector implements SiteSelectorInterface protected $seoPage; /** - * @var SiteInterface + * @var SiteInterface|null */ protected $site; diff --git a/src/Site/SiteSelectorInterface.php b/src/Site/SiteSelectorInterface.php index afb0e0ee9..37d07ba6e 100644 --- a/src/Site/SiteSelectorInterface.php +++ b/src/Site/SiteSelectorInterface.php @@ -25,7 +25,7 @@ interface SiteSelectorInterface { /** - * @return SiteInterface + * @return SiteInterface|null */ public function retrieve(); diff --git a/src/Twig/Extension/PageExtension.php b/src/Twig/Extension/PageExtension.php index f21cf4ec5..f14ed0a73 100644 --- a/src/Twig/Extension/PageExtension.php +++ b/src/Twig/Extension/PageExtension.php @@ -147,10 +147,14 @@ public function breadcrumb(?PageInterface $page = null, array $options = []) $breadcrumbs = $page->getParents(); if ($options['force_view_home_page'] && (!isset($breadcrumbs[0]) || 'homepage' !== $breadcrumbs[0]->getRouteName())) { + $site = $this->siteSelector->retrieve(); + + $homePage = false; try { - $homePage = $this->cmsManagerSelector->retrieve()->getPageByRouteName($this->siteSelector->retrieve(), 'homepage'); + if (null !== $site) { + $homePage = $this->cmsManagerSelector->retrieve()->getPageByRouteName($site, 'homepage'); + } } catch (PageNotFoundException $e) { - $homePage = false; } if ($homePage) { @@ -201,7 +205,7 @@ public function renderContainer($name, $page = null, array $options = []) try { if (null === $page) { $targetPage = $cms->getCurrentPage(); - } elseif (!$page instanceof PageInterface && \is_string($page)) { + } elseif (null !== $site && !$page instanceof PageInterface && \is_string($page)) { $targetPage = $cms->getInternalRoute($site, $page); } elseif ($page instanceof PageInterface) { $targetPage = $page;