/**
* Handle an exception by displaying an error message inside the Neos backend, if logged in and not displaying the live workspace.
*
* @param array $typoScriptPath path causing the exception
* @param \Exception $exception exception to handle
* @param integer $referenceCode
* @return string
*/
protected function handle($typoScriptPath, \Exception $exception, $referenceCode)
{
$handler = new ContextDependentHandler();
$handler->setRuntime($this->runtime);
$output = $handler->handleRenderingException($typoScriptPath, $exception);
$currentContext = $this->runtime->getCurrentContext();
/** @var NodeInterface $documentNode */
$documentNode = isset($currentContext['documentNode']) ? $currentContext['documentNode'] : null;
/** @var NodeInterface $node */
$node = isset($currentContext['node']) ? $currentContext['node'] : null;
$fluidView = $this->prepareFluidView();
$isBackend = false;
/** @var NodeInterface $siteNode */
$siteNode = isset($currentContext['site']) ? $currentContext['site'] : null;
if ($documentNode === null) {
// Actually we cannot be sure that $node is a document. But for fallback purposes this should be safe.
$documentNode = $siteNode ? $siteNode : $node;
}
if ($documentNode !== null && $documentNode->getContext()->getWorkspace()->getName() !== 'live' && $this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
$isBackend = true;
$fluidView->assign('metaData', $this->contentElementWrappingService->wrapCurrentDocumentMetadata($documentNode, '<div id="neos-document-metadata"></div>', $typoScriptPath));
}
$fluidView->assignMultiple(array('isBackend' => $isBackend, 'message' => $output, 'node' => $node));
return $fluidView->render();
}