/** * 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('TYPO3.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(); }
/** * renders the exception to nice html content element to display, edit, remove, ... * * @param string $typoScriptPath - path causing the exception * @param \Exception $exception - exception to handle * @param integer $referenceCode - might be unset * @return string */ protected function handle($typoScriptPath, \Exception $exception, $referenceCode) { $handler = new ContextDependentHandler(); $handler->setRuntime($this->runtime); $output = $handler->handleRenderingException($typoScriptPath, $exception); $currentContext = $this->getRuntime()->getCurrentContext(); if (isset($currentContext['node'])) { /** @var NodeInterface $node */ $node = $currentContext['node']; $applicationContext = $this->environment->getContext(); if ($applicationContext->isProduction() && $this->privilegeManager->isPrivilegeTargetGranted('TYPO3.Neos:Backend.GeneralAccess') && $node->getContext()->getWorkspaceName() !== 'live') { $output = '<div class="neos-rendering-exception"><div class="neos-rendering-exception-title">Failed to render element' . $output . '</div></div>'; } return $this->contentElementWrappingService->wrapContentObject($node, $output, $typoScriptPath); } return $output; }
/** * Finally evaluate the TypoScript path * * As PHP does not like throwing an exception here, we render any exception using the configured TypoScript exception * handler and will also catch and log any exceptions resulting from that as a last resort. * * @return string */ public function __toString() { try { return (string) $this->tsRuntime->evaluate($this->path); } catch (\Exception $exception) { try { return $this->tsRuntime->handleRenderingException($this->path, $exception); } catch (\Exception $exceptionHandlerException) { try { // Throwing an exception in __toString causes a fatal error, so if that happens we catch them and use the context dependent exception handler instead. $contextDependentExceptionHandler = new ContextDependentHandler(); $contextDependentExceptionHandler->setRuntime($this->tsRuntime); return $contextDependentExceptionHandler->handleRenderingException($this->path, $exception); } catch (\Exception $contextDepndentExceptionHandlerException) { $this->systemLogger->logException($contextDepndentExceptionHandlerException, array('path' => $this->path)); return sprintf('<!-- Exception while rendering exception in %s: %s (%s) -->', $this->path, $contextDepndentExceptionHandlerException->getMessage(), $contextDepndentExceptionHandlerException instanceof Exception ? 'see reference code ' . $contextDepndentExceptionHandlerException->getReferenceCode() . ' in log' : $contextDepndentExceptionHandlerException->getCode()); } } } }