Skip to content

Commit

Permalink
Catch possible null error when retriving site
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed May 1, 2020
1 parent edab41e commit f70c2b2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Block/ChildrenPagesBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Route/CmsPageRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Site/BaseSiteSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class BaseSiteSelector implements SiteSelectorInterface
protected $seoPage;

/**
* @var SiteInterface
* @var SiteInterface|null
*/
protected $site;

Expand Down
2 changes: 1 addition & 1 deletion src/Site/SiteSelectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
interface SiteSelectorInterface
{
/**
* @return SiteInterface
* @return SiteInterface|null
*/
public function retrieve();

Expand Down
10 changes: 7 additions & 3 deletions src/Twig/Extension/PageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f70c2b2

Please sign in to comment.