Skip to content

Commit

Permalink
BUGFIX: Prevent the Fusion Exception view to return blank page
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 16, 2024
1 parent e82f705 commit 2935495
Showing 1 changed file with 47 additions and 26 deletions.
73 changes: 47 additions & 26 deletions Neos.Neos/Classes/View/FusionExceptionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Neos\Flow\Mvc\View\AbstractView;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\Security\Context as SecurityContext;
use Neos\FluidAdaptor\View\StandaloneView;
use Neos\Fusion\Core\FusionGlobals;
use Neos\Fusion\Core\Runtime as FusionRuntime;
use Neos\Fusion\Core\RuntimeFactory;
Expand All @@ -38,6 +39,7 @@
use Neos\Neos\Domain\Repository\SiteRepository;
use Neos\Neos\Domain\Service\FusionService;
use Neos\Neos\Domain\Service\SiteNodeUtility;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionFailedException;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;

class FusionExceptionView extends AbstractView
Expand Down Expand Up @@ -107,7 +109,12 @@ public function render()

$httpRequest = $requestHandler->getHttpRequest();

$siteDetectionResult = SiteDetectionResult::fromRequest($httpRequest);
try {
$siteDetectionResult = SiteDetectionResult::fromRequest($httpRequest);
} catch (SiteDetectionFailedException) {
return $this->renderErrorWelcomeScreen();
}

$contentRepository = $this->contentRepositoryRegistry->get($siteDetectionResult->contentRepositoryId);
$fusionExceptionViewInternals = $this->contentRepositoryRegistry->buildService(
$siteDetectionResult->contentRepositoryId,
Expand All @@ -128,6 +135,10 @@ public function render()
);
}

if (!$currentSiteNode) {
return $this->renderErrorWelcomeScreen();
}

$request = ActionRequest::fromHttpRequest($httpRequest);
$request->setControllerPackageKey('Neos.Neos');
$request->setFormat('html');
Expand All @@ -144,32 +155,28 @@ public function render()
$securityContext = $this->objectManager->get(SecurityContext::class);
$securityContext->setRequest($request);

if ($currentSiteNode) {
$fusionRuntime = $this->getFusionRuntime($currentSiteNode, $controllerContext);

$this->setFallbackRuleFromDimension($dimensionSpacePoint);

$fusionRuntime->pushContextArray(array_merge(
$this->variables,
[
'node' => $currentSiteNode,
'documentNode' => $currentSiteNode,
'site' => $currentSiteNode,
'editPreviewMode' => null
]
));

try {
$output = $fusionRuntime->render('error');
return $this->extractBodyFromOutput($output);
} catch (RuntimeException $exception) {
throw $exception->getPrevious() ?: $exception;
} finally {
$fusionRuntime->popContext();
}
$fusionRuntime = $this->getFusionRuntime($currentSiteNode, $controllerContext);

$this->setFallbackRuleFromDimension($dimensionSpacePoint);

$fusionRuntime->pushContextArray(array_merge(
$this->variables,
[
'node' => $currentSiteNode,
'documentNode' => $currentSiteNode,
'site' => $currentSiteNode,
'editPreviewMode' => null
]
));

try {
$output = $fusionRuntime->render('error');
return $this->extractBodyFromOutput($output);
} catch (RuntimeException $exception) {
throw $exception->getPrevious() ?: $exception;
} finally {
$fusionRuntime->popContext();
}

return '';
}

/**
Expand Down Expand Up @@ -219,4 +226,18 @@ protected function getFusionRuntime(
}
return $this->fusionRuntime;
}

private function renderErrorWelcomeScreen(): string
{
// in case no neos site being there or no site node we cannot continue with the fusion exception view,
// as we wouldn't know the site and cannot get the site's root.fusion
// instead we render the welcome screen directly
// Todo hack to use fluid. Requires the Welcome.html to be ported to Fusion. PR -> https://github.com/neos/neos-development-collection/pull/4880
$view = StandaloneView::createWithOptions([
'templatePathAndFilename' => 'resource://Neos.Neos/Private/Templates/Error/Welcome.html',
'layoutRootPaths' => ['resource://Neos.Neos/Private/Layouts/']
]);
$view->assignMultiple($this->variables);
return $view->render();
}
}

0 comments on commit 2935495

Please sign in to comment.