From c57492f7db376045424c297ea88ad5f68301c33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kurfu=CC=88rst?= Date: Wed, 7 Mar 2018 15:22:12 +0100 Subject: [PATCH] BUGFIX: fall back to reloading the page if there was a Fusion rendering error when out-of-band rendering fixes: https://github.com/neos/form-builder/issues/17 --- .../Neos/Ui/Domain/Model/AbstractFeedback.php | 27 +++++++++++++++++++ .../Feedback/AbstractMessageFeedback.php | 3 ++- .../Model/Feedback/Operations/NodeCreated.php | 3 ++- .../Model/Feedback/Operations/Redirect.php | 3 ++- .../Operations/ReloadContentOutOfBand.php | 15 ++++++++++- .../Feedback/Operations/ReloadDocument.php | 3 ++- .../Model/Feedback/Operations/RemoveNode.php | 3 ++- .../Operations/RenderContentOutOfBand.php | 15 ++++++++++- .../Feedback/Operations/UpdateNodeInfo.php | 3 ++- .../Operations/UpdateWorkspaceInfo.php | 3 ++- .../Ui/Domain/Model/FeedbackCollection.php | 6 +---- .../Ui/Domain/Model/FeedbackInterface.php | 9 +++++++ 12 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 Classes/Neos/Neos/Ui/Domain/Model/AbstractFeedback.php diff --git a/Classes/Neos/Neos/Ui/Domain/Model/AbstractFeedback.php b/Classes/Neos/Neos/Ui/Domain/Model/AbstractFeedback.php new file mode 100644 index 0000000000..5a4ca35ae1 --- /dev/null +++ b/Classes/Neos/Neos/Ui/Domain/Model/AbstractFeedback.php @@ -0,0 +1,27 @@ + $this->getType(), + 'description' => $this->getDescription(), + 'payload' => $this->serializePayload($controllerContext) + ]; + } +} diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/AbstractMessageFeedback.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/AbstractMessageFeedback.php index 4d41311caf..37a81fdbdf 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/AbstractMessageFeedback.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/AbstractMessageFeedback.php @@ -11,10 +11,11 @@ * source code. */ +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -abstract class AbstractMessageFeedback implements FeedbackInterface +abstract class AbstractMessageFeedback extends AbstractFeedback { /** * @var string diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/NodeCreated.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/NodeCreated.php index dbe46d1556..a6c0df0bc8 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/NodeCreated.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/NodeCreated.php @@ -12,11 +12,12 @@ */ use Neos\Neos\Ui\ContentRepository\Service\NodeService; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -class NodeCreated implements FeedbackInterface +class NodeCreated extends AbstractFeedback { /** * @var NodeInterface diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/Redirect.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/Redirect.php index f2877f680b..bf3cafb01c 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/Redirect.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/Redirect.php @@ -3,12 +3,13 @@ use Neos\Flow\Annotations as Flow; use Neos\Neos\Service\LinkingService; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Fusion\Helper\NodeInfoHelper; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -class Redirect implements FeedbackInterface +class Redirect extends AbstractFeedback { /** * @var NodeInterface diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadContentOutOfBand.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadContentOutOfBand.php index 49b012f5ce..33658e5b03 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadContentOutOfBand.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadContentOutOfBand.php @@ -12,6 +12,8 @@ */ use Neos\Flow\Annotations as Flow; +use Neos\Fusion\Exception\MissingFusionObjectException; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Neos\View\FusionView as FusionView; @@ -19,7 +21,7 @@ use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress; use Neos\Fusion\Core\Cache\ContentCache; -class ReloadContentOutOfBand implements FeedbackInterface +class ReloadContentOutOfBand extends AbstractFeedback { /** * @var NodeInterface @@ -153,4 +155,15 @@ protected function renderContent(ControllerContext $controllerContext) return $fusionView->render(); } + + public function serialize(ControllerContext $controllerContext) + { + try { + return parent::serialize($controllerContext); + } catch (MissingFusionObjectException $e) { + // in case there was a rendering error, we just try to reload the document as fallback. Needed + // e.g. when adding validators to Neos.FormBuilder + return (new ReloadDocument())->serialize($controllerContext); + } + } } diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadDocument.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadDocument.php index 2b182129d5..1a67891704 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadDocument.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/ReloadDocument.php @@ -11,10 +11,11 @@ * source code. */ +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -class ReloadDocument implements FeedbackInterface +class ReloadDocument extends AbstractFeedback { /** diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RemoveNode.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RemoveNode.php index 2133904da2..482e4637a0 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RemoveNode.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RemoveNode.php @@ -11,11 +11,12 @@ * source code. */ +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -class RemoveNode implements FeedbackInterface +class RemoveNode extends AbstractFeedback { /** * @var NodeInterface diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php index 7deaa008a3..0ae19842b7 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/RenderContentOutOfBand.php @@ -12,6 +12,8 @@ */ use Neos\Flow\Annotations as Flow; +use Neos\Fusion\Exception\MissingFusionObjectException; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Neos\View\FusionView as FusionView; @@ -19,7 +21,7 @@ use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress; use Neos\Fusion\Core\Cache\ContentCache; -class RenderContentOutOfBand implements FeedbackInterface +class RenderContentOutOfBand extends AbstractFeedback { /** * @var NodeInterface @@ -209,4 +211,15 @@ protected function renderContent(ControllerContext $controllerContext) return $fusionView->render(); } + + public function serialize(ControllerContext $controllerContext) + { + try { + return parent::serialize($controllerContext); + } catch (MissingFusionObjectException $e) { + // in case there was a rendering error, we just try to reload the document as fallback. Needed + // e.g. when adding validators to Neos.FormBuilder + return (new ReloadDocument())->serialize($controllerContext); + } + } } diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateNodeInfo.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateNodeInfo.php index af990b8124..d9803a37bd 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateNodeInfo.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateNodeInfo.php @@ -12,12 +12,13 @@ */ use Neos\Flow\Annotations as Flow; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Fusion\Helper\NodeInfoHelper; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Flow\Mvc\Controller\ControllerContext; -class UpdateNodeInfo implements FeedbackInterface +class UpdateNodeInfo extends AbstractFeedback { /** * @var NodeInterface diff --git a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php index 1df88a94b7..1c42ae6b4f 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/Feedback/Operations/UpdateWorkspaceInfo.php @@ -13,11 +13,12 @@ use Neos\Flow\Annotations as Flow; use Neos\ContentRepository\Domain\Model\Workspace; +use Neos\Neos\Ui\Domain\Model\AbstractFeedback; use Neos\Neos\Ui\Domain\Model\FeedbackInterface; use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService; use Neos\Flow\Mvc\Controller\ControllerContext; -class UpdateWorkspaceInfo implements FeedbackInterface +class UpdateWorkspaceInfo extends AbstractFeedback { /** * @var Workspace diff --git a/Classes/Neos/Neos/Ui/Domain/Model/FeedbackCollection.php b/Classes/Neos/Neos/Ui/Domain/Model/FeedbackCollection.php index 40fead9c6b..c0bff335b2 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/FeedbackCollection.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/FeedbackCollection.php @@ -67,11 +67,7 @@ public function jsonSerialize() $feedbacks = []; foreach ($this->feedbacks as $feedback) { - $feedbacks[] = [ - 'type' => $feedback->getType(), - 'description' => $feedback->getDescription(), - 'payload' => $feedback->serializePayload($this->controllerContext) - ]; + $feedbacks[]= $feedback->serialize($this->controllerContext); } return [ diff --git a/Classes/Neos/Neos/Ui/Domain/Model/FeedbackInterface.php b/Classes/Neos/Neos/Ui/Domain/Model/FeedbackInterface.php index 9b7fb129d9..4ca4bd4f97 100644 --- a/Classes/Neos/Neos/Ui/Domain/Model/FeedbackInterface.php +++ b/Classes/Neos/Neos/Ui/Domain/Model/FeedbackInterface.php @@ -15,6 +15,15 @@ interface FeedbackInterface { + /** + * main entry point for serializing the feedback before it is sent to the UI. Usually implemented + * in AbstractFeedback, but can be overridden to implement fallback logic in case of errors. + * + * @param ControllerContext $controllerContext + * @return array + */ + public function serialize(ControllerContext $controllerContext); + /** * Get the type identifier *