Skip to content

Commit

Permalink
4622 - Allow other views than Fusion for out-of-band rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Oct 20, 2023
1 parent d0435d8 commit 114c0e5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Domain\Model\Feedback\Operations;

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

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

public function resolveView(): AbstractView&RenderingEntryPointAware
{
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 RenderingEntryPointAware) {
throw new \DomainException(
'Declared view (' . $this->viewObjectName . ') does not implement ' . RenderingEntryPointAware::class
. ' required for out-of-band rendering',
1697821364
);
}

return $view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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 Psr\Http\Message\ResponseInterface;

class ReloadContentOutOfBand extends AbstractFeedback
Expand Down Expand Up @@ -53,6 +52,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 +139,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,6 @@
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 Psr\Http\Message\ResponseInterface;

class RenderContentOutOfBand extends AbstractFeedback
Expand Down Expand Up @@ -63,6 +65,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 +188,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
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\View\FusionView'
Flow:
security:
authentication:
Expand Down

0 comments on commit 114c0e5

Please sign in to comment.