diff --git a/Classes/Backend/Preview/PreviewRenderer.php b/Classes/Backend/Preview/PreviewRenderer.php index c6a4a329..a63828f1 100644 --- a/Classes/Backend/Preview/PreviewRenderer.php +++ b/Classes/Backend/Preview/PreviewRenderer.php @@ -26,7 +26,9 @@ use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility; use TYPO3\CMS\Core\Domain\RecordFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Fluid\View\StandaloneView; +use TYPO3\CMS\Core\View\ViewFactoryData; +use TYPO3\CMS\Core\View\ViewFactoryInterface; +use TYPO3\CMS\Core\View\ViewInterface; /** * Sets up Fluid and applies the same DataProcessor as the frontend to the data record. @@ -41,6 +43,7 @@ public function __construct( protected ContentBlockRegistry $contentBlockRegistry, protected ContentBlockDataDecorator $contentBlockDataDecorator, protected RootPathsSettings $rootPathsSettings, + protected ViewFactoryInterface $viewFactory, ) {} public function renderPageModulePreviewContent(GridColumnItem $item): string @@ -71,7 +74,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string $data = $this->contentBlockDataDecorator->decorate($resolvedRecord, $item->getContext()); $view = $this->createView($contentBlockPrivatePath, $request, $item); $view->assign('data', $data); - $result = (string)$view->render(); + $result = $view->render(); return $result; } @@ -79,15 +82,17 @@ protected function createView( string $contentBlockPrivatePath, ServerRequestInterface $request, GridColumnItem $item - ): StandaloneView { + ): ViewInterface { $pageUid = $item->getContext()->getPageId(); - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setLayoutRootPaths($this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid)); - $view->setPartialRootPaths($this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid)); - $view->setTemplateRootPaths([$contentBlockPrivatePath]); - $view->setTemplate(ContentBlockPathUtility::getBackendPreviewFileNameWithoutExtension()); - $view->setRequest($request); - return $view; + $partialRootPaths = $this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid); + $layoutRootPaths = $this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid); + $viewFactoryData = new ViewFactoryData( + partialRootPaths: $partialRootPaths, + layoutRootPaths: $layoutRootPaths, + templatePathAndFilename: $contentBlockPrivatePath . '/' . ContentBlockPathUtility::getBackendPreviewFileName(), + request: $request + ); + return $this->viewFactory->create($viewFactoryData); } /**