Skip to content

Commit

Permalink
[TASK] Fix backend previews
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov committed Sep 20, 2024
1 parent dd9156d commit 455944a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Classes/Backend/Preview/PreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -71,23 +74,25 @@ 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;
}

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);
}

/**
Expand Down

0 comments on commit 455944a

Please sign in to comment.