Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: 4622 - decouple out-of-band rendering from Fusion #3647

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Neos\Neos\Ui\Domain\Model\AbstractFeedback;
use Neos\Neos\Ui\Domain\Model\FeedbackInterface;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Neos\View\FusionView;
use Neos\Neos\Ui\View\OutOfBandRenderingViewFactory;
use Psr\Http\Message\ResponseInterface;

class ReloadContentOutOfBand extends AbstractFeedback
Expand Down Expand Up @@ -53,6 +53,9 @@ class ReloadContentOutOfBand extends AbstractFeedback
#[Flow\Inject]
protected RenderingModeService $renderingModeService;

#[Flow\Inject]
protected OutOfBandRenderingViewFactory $outOfBandRenderingViewFactory;

public function setNode(Node $node): void
{
$this->node = $node;
Expand Down Expand Up @@ -137,14 +140,14 @@ protected function renderContent(ControllerContext $controllerContext): string|R
if ($this->nodeDomAddress) {
$renderingMode = $this->renderingModeService->findByCurrentUser();

$fusionView = new FusionView();
$fusionView->setControllerContext($controllerContext);
$fusionView->setOption('renderingModeName', $renderingMode->name);
$view = $this->outOfBandRenderingViewFactory->resolveView();
$view->setControllerContext($controllerContext);
$view->setOption('renderingModeName', $renderingMode->name);

$fusionView->assign('value', $this->node);
$fusionView->setFusionPath($this->nodeDomAddress->getFusionPathForContentRendering());
$view->assign('value', $this->node);
$view->setRenderingEntryPoint($this->nodeDomAddress->getFusionPathForContentRendering());

return $fusionView->render();
return $view->render();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
namespace Neos\Neos\Ui\Domain\Model\Feedback\Operations;

/*
* This file is part of the Neos.Neos.Ui package.
Expand All @@ -11,6 +10,10 @@
* source code.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\Domain\Model\Feedback\Operations;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Neos\Domain\Service\RenderingModeService;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
Expand All @@ -23,7 +26,7 @@
use Neos\Neos\Ui\Domain\Model\AbstractFeedback;
use Neos\Neos\Ui\Domain\Model\FeedbackInterface;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Neos\View\FusionView;
use Neos\Neos\Ui\View\OutOfBandRenderingViewFactory;
use Psr\Http\Message\ResponseInterface;

class RenderContentOutOfBand extends AbstractFeedback
Expand Down Expand Up @@ -63,6 +66,9 @@ class RenderContentOutOfBand extends AbstractFeedback
#[Flow\Inject]
protected RenderingModeService $renderingModeService;

#[Flow\Inject]
protected OutOfBandRenderingViewFactory $outOfBandRenderingViewFactory;

public function setNode(Node $node): void
{
$this->node = $node;
Expand Down Expand Up @@ -183,14 +189,14 @@ protected function renderContent(ControllerContext $controllerContext): string|R
if ($parentDomAddress) {
$renderingMode = $this->renderingModeService->findByCurrentUser();

$fusionView = new FusionView();
$fusionView->setControllerContext($controllerContext);
$fusionView->setOption('renderingModeName', $renderingMode->name);
$view = $this->outOfBandRenderingViewFactory->resolveView();
$view->setControllerContext($controllerContext);
$view->setOption('renderingModeName', $renderingMode->name);

$fusionView->assign('value', $parentNode);
$fusionView->setFusionPath($parentDomAddress->getFusionPath());
$view->assign('value', $parentNode);
$view->setRenderingEntryPoint($parentDomAddress->getFusionPath());

return $fusionView->render();
return $view->render();
}
}

Expand Down
30 changes: 30 additions & 0 deletions Classes/View/OutOfBandRenderingCapable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* 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.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\View;

use Psr\Http\Message\ResponseInterface;

/**
* The interface for views capable of out-of-band rendering by accepting string serialized entry points
*/
interface OutOfBandRenderingCapable
{
/**
* Set the rendering entry point, e.g. a Fusion path to use for rendering
*/
public function setRenderingEntryPoint(string $renderingEntryPoint): void;

public function render(): string|ResponseInterface;
}
28 changes: 28 additions & 0 deletions Classes/View/OutOfBandRenderingFusionView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* 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.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\View;

use Neos\Neos\View\FusionView;

/**
* A Fusion view capable of out-of-band rendering
*/
class OutOfBandRenderingFusionView extends FusionView implements OutOfBandRenderingCapable
{
public function setRenderingEntryPoint(string $renderingEntryPoint): void
{
$this->setFusionPath($renderingEntryPoint);
}
}
54 changes: 54 additions & 0 deletions Classes/View/OutOfBandRenderingViewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* 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.
*/

declare(strict_types=1);

namespace Neos\Neos\Ui\View;

use Neos\Flow\Mvc\View\AbstractView;
use Neos\Flow\Annotations as Flow;

class OutOfBandRenderingViewFactory
{
/**
* @phpstan-var class-string
*/
#[Flow\InjectConfiguration(path: 'outOfBandRendering.viewObjectName')]
protected string $viewObjectName;

public function resolveView(): AbstractView&OutOfBandRenderingCapable
{
if (!class_exists($this->viewObjectName)) {
throw new \DomainException(
'Declared view for out of band rendering (' . $this->viewObjectName . ') does not exist',
1697821296
);
}
$view = new $this->viewObjectName();
if (!$view instanceof AbstractView) {
throw new \DomainException(
'Declared view (' . $this->viewObjectName . ') does not implement ' . AbstractView::class
. ' required for out-of-band rendering',
1697821429
);
}
if (!$view instanceof OutOfBandRenderingCapable) {
throw new \DomainException(
'Declared view (' . $this->viewObjectName . ') does not implement ' . OutOfBandRenderingCapable::class
. ' required for out-of-band rendering',
1697821364
);
}

return $view;
}
}
2 changes: 2 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Neos:
'Neos.Neos.Ui:MoveBefore': Neos\Neos\Ui\Domain\Model\Changes\MoveBefore
'Neos.Neos.Ui:MoveAfter': Neos\Neos\Ui\Domain\Model\Changes\MoveAfter
'Neos.Neos.Ui:MoveInto': Neos\Neos\Ui\Domain\Model\Changes\MoveInto
outOfBandRendering:
viewObjectName: 'Neos\Neos\Ui\View\OutOfBandRenderingFusionView'
Flow:
security:
authentication:
Expand Down
Loading