Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to method assignMultiple\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method hasTemplate\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method render\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method setLayoutRootPaths\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method setPartialRootPaths\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method setTemplate\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method setTemplateRootPaths\\(\\) on an unknown class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Class TYPO3\\\\CMS\\\\Fluid\\\\View\\\\StandaloneView not found\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
Expand All @@ -54,12 +14,3 @@ parameters:
message: "#^Parameter \\#1 \\$row of method B13\\\\Backendpreviews\\\\Service\\\\DatabaseRowService\\:\\:extendRow\\(\\) expects array, TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface given\\.$#"
count: 1
path: ../Classes/Listener/PageContentPreviewRendering.php

-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryBuilder\\:\\:add\\(\\)\\.$#"
count: 1
path: ../Classes/ViewHelpers/GetDatabaseRecordViewHelper.php
-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\IconProvider\\\\FontawesomeIconProvider not found\\.$#"
count: 2
path: ../Classes/Listener/BootCompleted.php
87 changes: 0 additions & 87 deletions Build/phpstan-baseline12.neon

This file was deleted.

8 changes: 0 additions & 8 deletions Build/phpstan-baseline13.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,3 @@ parameters:
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\BackendUserAuthentication\\:\\:checkRecordEditAccess\\(\\)\\.$#"
count: 1
path: ../Classes/Service/DatabaseRowService.php
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryBuilder\\:\\:add\\(\\)\\.$#"
count: 1
path: ../Classes/ViewHelpers/GetDatabaseRecordViewHelper.php
-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\IconProvider\\\\FontawesomeIconProvider not found\\.$#"
count: 2
path: ../Classes/Listener/BootCompleted.php
4 changes: 1 addition & 3 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ includes:
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/BackendPreviewRenderer.php
- %currentWorkingDirectory%/Classes
8 changes: 0 additions & 8 deletions Build/phpstan12.neon

This file was deleted.

4 changes: 1 addition & 3 deletions Build/phpstan13.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ includes:
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/BackendPreviewRenderer.php
- %currentWorkingDirectory%/Classes
93 changes: 49 additions & 44 deletions Classes/Backend/Preview/ContentPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,23 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\View\ViewInterface;
use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;

class ContentPreview
{
public function render(RecordInterface $record, PageLayoutContext $context): ?string
{
$previewConfiguration = BackendUtility::getPagesTSconfig($record->getPid())['mod.']['web_layout.']['tt_content.']['preview.'] ?? [];
if (!$previewConfiguration) {
// Early return in case no preview configuration can be found
$previewConfiguration = $this->getPreviewConfiguration((int)$record->getPid());
if ($previewConfiguration === null) {
return null;
}

$fluidConfiguration = $previewConfiguration['view.'] ?? [];
if (!$fluidConfiguration) {
// Early return in case no fluid template configuration can be found
return null;
}

$templateConfiguration = $previewConfiguration['template.'] ?? [];
$cType = $record->getRecordType();
if (!empty($templateConfiguration[$cType])) {
$fluidTemplateName = $templateConfiguration[$cType];
} else {
$fluidTemplateName = $cType;
}
$viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class);
$view = $viewFactory->create(
new ViewFactoryData(
$fluidConfiguration['templateRootPaths.'] ?? null,
$fluidConfiguration['partialRootPaths.'] ?? null,
$fluidConfiguration['layoutRootPaths.'] ?? null,
null,
$context->getCurrentRequest()
)
);
$templateConfiguration = $previewConfiguration['template.'] ?? [];
$fluidTemplateName = !empty($templateConfiguration[$cType]) ? $templateConfiguration[$cType] : $cType;

$view = $this->createView($previewConfiguration['view.'], $context);
$data = GeneralUtility::makeInstance(DatabaseRowService::class)->getAdditionalDataForView($record, $context);
$view->assignMultiple($data);
$view->assign('record', $record);
Expand All @@ -66,17 +46,16 @@ public function render(RecordInterface $record, PageLayoutContext $context): ?st
return null;
}

public function renderLegacy(array $row): ?string
/**
* Render path for TYPO3 v13, where the page module still passes the content element as an array
* instead of a RecordInterface (see Breaking-92434).
*
* @param array<string, mixed> $row
*/
public function renderLegacy(array $row, PageLayoutContext $context): ?string
{
$previewConfiguration = BackendUtility::getPagesTSconfig($row['pid'])['mod.']['web_layout.']['tt_content.']['preview.'] ?? [];
if (!$previewConfiguration) {
// Early return in case no preview configuration can be found
return null;
}

$fluidConfiguration = $previewConfiguration['view.'] ?? [];
if (!$fluidConfiguration) {
// Early return in case no fluid template configuration can be found
$previewConfiguration = $this->getPreviewConfiguration((int)$row['pid']);
if ($previewConfiguration === null) {
return null;
}

Expand All @@ -89,16 +68,42 @@ public function renderLegacy(array $row): ?string
$fluidTemplateName = $row['CType'];
}

$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths($fluidConfiguration['layoutRootPaths.'] ?? []);
$view->setPartialRootPaths($fluidConfiguration['partialRootPaths.'] ?? []);
$view->setTemplateRootPaths($fluidConfiguration['templateRootPaths.'] ?? []);
$view->setTemplate($fluidTemplateName);
$view = $this->createView($previewConfiguration['view.'], $context);
$view->assignMultiple($row);

if ($view->hasTemplate()) {
return $view->render();
try {
return $view->render($fluidTemplateName);
} catch (InvalidTemplateResourceException) {
}
return null;
}

/**
* @return array<string, mixed>|null
*/
protected function getPreviewConfiguration(int $pid): ?array
{
$previewConfiguration = BackendUtility::getPagesTSconfig($pid)['mod.']['web_layout.']['tt_content.']['preview.'] ?? [];
// Early return in case no preview (or fluid template) configuration can be found
if (!$previewConfiguration || empty($previewConfiguration['view.'])) {
return null;
}
return $previewConfiguration;
}

/**
* @param array<string, mixed> $fluidConfiguration
*/
protected function createView(array $fluidConfiguration, PageLayoutContext $context): ViewInterface
{
$viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class);
return $viewFactory->create(
new ViewFactoryData(
$fluidConfiguration['templateRootPaths.'] ?? null,
$fluidConfiguration['partialRootPaths.'] ?? null,
$fluidConfiguration['layoutRootPaths.'] ?? null,
null,
$context->getCurrentRequest()
)
);
}
}
2 changes: 1 addition & 1 deletion Classes/Backend/Preview/StandardContentPreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
if ($record instanceof RecordInterface) {
$content = $contentPreview->render($record, $context);
} else {
$content = $contentPreview->renderLegacy($record);
$content = $contentPreview->renderLegacy($record, $context);
}
if ($content !== null) {
return $content;
Expand Down
62 changes: 0 additions & 62 deletions Classes/Hooks/BackendPreviewRenderer.php

This file was deleted.

Loading
Loading