diff --git a/Classes/Backend/Preview/PageLayout.php b/Classes/Backend/Preview/PageLayout.php index 6bbd5240..ac81e180 100644 --- a/Classes/Backend/Preview/PageLayout.php +++ b/Classes/Backend/Preview/PageLayout.php @@ -17,6 +17,7 @@ namespace TYPO3\CMS\ContentBlocks\Backend\Preview; +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent; use TYPO3\CMS\Backend\Module\ModuleData; use TYPO3\CMS\Backend\Utility\BackendUtility; @@ -28,7 +29,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; /** * @internal Not part of TYPO3's public API. @@ -42,6 +45,7 @@ public function __construct( protected ContentBlockDataDecorator $contentBlockDataDecorator, protected RootPathsSettings $rootPathsSettings, protected ContentTypeResolver $contentTypeResolver, + protected ViewFactoryInterface $viewFactory, ) {} public function __invoke(ModifyPageLayoutContentEvent $event): void @@ -74,22 +78,24 @@ public function __invoke(ModifyPageLayoutContentEvent $event): void return; } $contentBlockData = $this->contentBlockDataDecorator->decorate($resolvedRecord); - $view = $this->createView($contentTypeDefinition, $pageUid); - $view->setRequest($request); + $view = $this->createView($contentTypeDefinition, $pageUid, $request); $view->assign('data', $contentBlockData); - $renderedView = (string)$view->render(); + $renderedView = $view->render(); $event->addHeaderContent($renderedView); } - protected function createView(ContentTypeInterface $contentTypeDefinition, int $pageUid): StandaloneView + protected function createView(ContentTypeInterface $contentTypeDefinition, int $pageUid, ServerRequestInterface $request): ViewInterface { $contentBlockPrivatePath = $this->getContentBlockPrivatePath($contentTypeDefinition); - $view = GeneralUtility::makeInstance(StandaloneView::class); - $view->setLayoutRootPaths($this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid)); - $view->setPartialRootPaths($this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid)); - $view->setTemplateRootPaths([$contentBlockPrivatePath]); - $view->setTemplate(ContentBlockPathUtility::getBackendPreviewFileNameWithoutExtension()); - return $view; + $layoutRootPaths = $this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid); + $partialRootPaths = $this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid); + $viewData = new ViewFactoryData( + partialRootPaths: $partialRootPaths, + layoutRootPaths: $layoutRootPaths, + templatePathAndFilename: $contentBlockPrivatePath . '/' . ContentBlockPathUtility::getBackendPreviewFileName(), + request: $request, + ); + return $this->viewFactory->create($viewData); } /** diff --git a/Classes/Utility/ContentBlockPathUtility.php b/Classes/Utility/ContentBlockPathUtility.php index 5b6de1b8..a619da76 100644 --- a/Classes/Utility/ContentBlockPathUtility.php +++ b/Classes/Utility/ContentBlockPathUtility.php @@ -45,11 +45,6 @@ public static function getBackendPreviewFileName(): string return 'preview.html'; } - public static function getBackendPreviewFileNameWithoutExtension(): string - { - return substr(self::getBackendPreviewFileName(), 0, -5); - } - public static function getBackendPreviewPath(): string { return self::getTemplatesFolder() . '/' . self::getBackendPreviewFileName(); @@ -60,11 +55,6 @@ public static function getFrontendTemplateFileName(): string return 'frontend.html'; } - public static function getFrontendTemplateFileNameWithoutExtension(): string - { - return substr(self::getFrontendTemplateFileName(), 0, -5); - } - public static function getFrontendTemplatePath(): string { return self::getTemplatesFolder() . '/' . self::getFrontendTemplateFileName();