diff --git a/Neos.Neos/Classes/View/FusionExceptionView.php b/Neos.Neos/Classes/View/FusionExceptionView.php index 59cddcd535d..c0c990a75e9 100644 --- a/Neos.Neos/Classes/View/FusionExceptionView.php +++ b/Neos.Neos/Classes/View/FusionExceptionView.php @@ -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; @@ -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 @@ -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, @@ -128,6 +135,10 @@ public function render() ); } + if (!$currentSiteNode) { + return $this->renderErrorWelcomeScreen(); + } + $request = ActionRequest::fromHttpRequest($httpRequest); $request->setControllerPackageKey('Neos.Neos'); $request->setFormat('html'); @@ -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 ''; } /** @@ -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(); + } }