Skip to content

Commit

Permalink
TASK: Adjust to ViewInterface change in Neos.Flow and Neos.Neos
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 17, 2024
1 parent 98ecd6b commit a7b193d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function serializePayload(ControllerContext $controllerContext): array
/**
* Render the node
*/
protected function renderContent(ControllerContext $controllerContext): string|ResponseInterface
protected function renderContent(ControllerContext $controllerContext): string
{
if (!is_null($this->node)) {
$cacheTags = $this->cachingHelper->nodeTag($this->getNode());
Expand All @@ -150,7 +150,12 @@ protected function renderContent(ControllerContext $controllerContext): string|R
$view->assign('value', $this->node);
$view->setRenderingEntryPoint($this->nodeDomAddress->getFusionPathForContentRendering());

return $view->render();
$content = $view->render();
if ($content instanceof ResponseInterface) {
// todo should not happen, as we never render a full Neos.Neos:Page here?
return $content->getBody()->getContents();
}
return $content->getContents();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function serializePayload(ControllerContext $controllerContext): array
/**
* Render the node
*/
protected function renderContent(ControllerContext $controllerContext): string|ResponseInterface
protected function renderContent(ControllerContext $controllerContext): string
{
if (is_null($this->node)) {
return '';
Expand All @@ -199,7 +199,12 @@ protected function renderContent(ControllerContext $controllerContext): string|R
$view->assign('value', $parentNode);
$view->setRenderingEntryPoint($parentDomAddress->getFusionPath());

return $view->render();
$content = $view->render();
if ($content instanceof ResponseInterface) {
// todo should not happen, as we never render a full Neos.Neos:Page here?
return $content->getBody()->getContents();
}
return $content->getContents();
}
}

Expand Down
27 changes: 14 additions & 13 deletions Classes/Fusion/ExceptionHandler/PageExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
use GuzzleHttp\Psr7\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Exception;
use Neos\Flow\Mvc\Controller\Arguments;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\View\ViewInterface;
use Neos\Flow\Utility\Environment;
use Neos\FluidAdaptor\View\StandaloneView;
use Neos\Fusion\Core\ExceptionHandlers\AbstractRenderingExceptionHandler;
use Neos\Fusion\Core\ExceptionHandlers\HtmlMessageHandler;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

/**
* A page exception handler for the new UI.
Expand All @@ -37,12 +39,6 @@ class PageExceptionHandler extends AbstractRenderingExceptionHandler
*/
protected $responseFactory;

/**
* @Flow\Inject
* @var StreamFactoryInterface
*/
protected $contentFactory;

/**
* @Flow\Inject
* @var Environment
Expand Down Expand Up @@ -78,13 +74,11 @@ protected function handle($fusionPath, \Exception $exception, $referenceCode): s
* Renders an actual HTTP response including the correct status and cache control header.
*
* @param \Exception $exception the exception
* @param string $bodyContent
* @return string
*/
protected function wrapHttpResponse(\Exception $exception, string $bodyContent): string
protected function wrapHttpResponse(\Exception $exception, StreamInterface $bodyContent): string
{
$response = $this->responseFactory->createResponse($exception instanceof Exception ? $exception->getStatusCode() : 500)
->withBody($this->contentFactory->createStream($bodyContent))
->withBody($bodyContent)
->withHeader('Cache-Control', 'no-store');

return Message::toString($response);
Expand All @@ -99,13 +93,20 @@ protected function wrapHttpResponse(\Exception $exception, string $bodyContent):
protected function prepareFluidView(): ViewInterface
{
$fluidView = new StandaloneView();
$fluidView->setControllerContext($this->runtime->getControllerContext());
$fluidView->setControllerContext(
new ControllerContext(
$this->runtime->getControllerContext()->getRequest(),
$this->runtime->getControllerContext()->getResponse(),
new Arguments(),
$this->runtime->getControllerContext()->getUriBuilder()
)
);
$fluidView->setFormat('html');
$fluidView->setTemplatePathAndFilename('resource://Neos.Neos.Ui/Private/Templates/Error/ErrorMessage.html');

$guestNotificationScript = new StandaloneView();
$guestNotificationScript->setTemplatePathAndFilename('resource://Neos.Neos.Ui/Private/Templates/Backend/GuestNotificationScript.html');
$fluidView->assign('guestNotificationScript', $guestNotificationScript->render());
$fluidView->assign('guestNotificationScript', $guestNotificationScript->render()->getContents());

return $fluidView;
}
Expand Down
8 changes: 6 additions & 2 deletions Classes/Presentation/ApplicationView.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
use Neos\Flow\Mvc\View\AbstractView;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Flow\Security\Context as SecurityContext;
use Neos\Http\Factories\StreamFactoryTrait;
use Neos\Neos\Service\UserService;
use Neos\Neos\Ui\Domain\Service\StyleAndJavascriptInclusionService;
use Psr\Http\Message\StreamInterface;

/**
* @internal This view is meant to be used exclusively in conjunction with
Expand All @@ -30,6 +32,8 @@
#[Flow\Scope("singleton")]
final class ApplicationView extends AbstractView
{
use StreamFactoryTrait;

#[Flow\Inject]
protected UserService $userService;

Expand All @@ -54,7 +58,7 @@ final class ApplicationView extends AbstractView
'title' => [null, 'The application title which will be used as the HTML <title>.', 'string'],
];

public function render(): string
public function render(): StreamInterface
{
$result = '<!DOCTYPE html>';
$result .= '<html lang="' . $this->renderLang() . '">';
Expand All @@ -66,7 +70,7 @@ public function render(): string
$result .= '</body>';
$result .= '</html>';

return $result;
return $this->createStream($result);
}

private function renderLang(): string
Expand Down
3 changes: 2 additions & 1 deletion Classes/View/OutOfBandRenderingCapable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Neos\Neos\Ui\View;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

/**
* The interface for views capable of out-of-band rendering by accepting string serialized entry points
Expand All @@ -27,5 +28,5 @@ interface OutOfBandRenderingCapable
*/
public function setRenderingEntryPoint(string $renderingEntryPoint): void;

public function render(): string|ResponseInterface;
public function render(): ResponseInterface|StreamInterface;
}

0 comments on commit a7b193d

Please sign in to comment.