Skip to content

Commit

Permalink
BUGFIX: fall back to reloading the page if there was a Fusion renderi…
Browse files Browse the repository at this point in the history
…ng error when out-of-band rendering

fixes: neos/form-builder#17
  • Loading branch information
skurfuerst committed Mar 7, 2018
1 parent 8d9ef3b commit c57492f
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 14 deletions.
27 changes: 27 additions & 0 deletions Classes/Neos/Neos/Ui/Domain/Model/AbstractFeedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Neos\Neos\Ui\Domain\Model;

/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\Flow\Mvc\Controller\ControllerContext;

abstract class AbstractFeedback implements FeedbackInterface
{
public function serialize(ControllerContext $controllerContext)
{
return [
'type' => $this->getType(),
'description' => $this->getDescription(),
'payload' => $this->serializePayload($controllerContext)
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
*/

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;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Fusion\Core\Cache\ContentCache;

class ReloadContentOutOfBand implements FeedbackInterface
class ReloadContentOutOfBand extends AbstractFeedback
{
/**
* @var NodeInterface
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
*/

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;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Fusion\Core\Cache\ContentCache;

class RenderContentOutOfBand implements FeedbackInterface
class RenderContentOutOfBand extends AbstractFeedback
{
/**
* @var NodeInterface
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Classes/Neos/Neos/Ui/Domain/Model/FeedbackCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
9 changes: 9 additions & 0 deletions Classes/Neos/Neos/Ui/Domain/Model/FeedbackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit c57492f

Please sign in to comment.