Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
TYPO3: [ '12', '13', '14' ]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install composer dependencies TYPO3 14
if: matrix.TYPO3 == '14'
run: |
composer install --no-progress --no-interaction
- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer require typo3/cms-core:^13.4 typo3/cms-fluid:^13.4 --no-progress --no-interaction --dev -W
- name: Install composer dependencies TYPO3 12
if: matrix.TYPO3 == '12'
run: |
composer require typo3/cms-core:^12.4 typo3/cms-extbase:^12.4 typo3/cms-fluid:^12.4 --no-progress --no-interaction --dev -W
- name: Phpcsfix
run: .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no
- name: Phpstan 13
if: matrix.TYPO3 == '13'
run: .Build/bin/phpstan analyze -c Build/phpstan13.neon
- name: Phpstan 14
if: matrix.TYPO3 == '14'
run: .Build/bin/phpstan analyze -c Build/phpstan.neon
- name: Phpstan 12
if: matrix.TYPO3 == '12'
run: .Build/bin/phpstan analyze -c Build/phpstan12.neon
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.Build/
Build/phpunit/.phpunit.cache
var/
composer.lock
.php-cs-fixer.cache
.env
.idea
11 changes: 11 additions & 0 deletions Build/php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->exclude(['var'])->in(__DIR__ . '/..');
$config->addRules([
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
]);
return $config;
61 changes: 61 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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
path: ../Classes/Backend/Preview/StandardContentPreviewRenderer.php

-
message: "#^Parameter \\#1 \\$record of method TYPO3\\\\CMS\\\\Backend\\\\View\\\\Event\\\\PageContentPreviewRenderingEvent\\:\\:setRecord\\(\\) expects TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface, array given\\.$#"
count: 1
path: ../Classes/Listener/PageContentPreviewRendering.php

-
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
46 changes: 46 additions & 0 deletions Build/phpstan-baseline12.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Backend\\\\View\\\\PageLayoutContext\\:\\:getCurrentRequest\\(\\)\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

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

-
message: "#^Call to method getPid\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Call to method getRecordType\\(\\) on an unknown class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

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

-
message: "#^Instantiated class TYPO3\\\\CMS\\\\Core\\\\View\\\\ViewFactoryData not found\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Parameter \\$record of method B13\\\\Backendpreviews\\\\Backend\\\\Preview\\\\ContentPreview\\:\\:render\\(\\) has invalid type TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface\\.$#"
count: 1
path: ../Classes/Backend/Preview/ContentPreview.php

-
message: "#^Class TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface not found\\.$#"
count: 1
path: ../Classes/Backend/Preview/StandardContentPreviewRenderer.php

-
message: "#^Instanceof between array and TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface will always evaluate to false\\.$#"
count: 1
path: ../Classes/Backend/Preview/StandardContentPreviewRenderer.php
11 changes: 11 additions & 0 deletions Build/phpstan-baseline13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Instanceof between array and TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface will always evaluate to false\\.$#"
count: 1
path: ../Classes/Backend/Preview/StandardContentPreviewRenderer.php

-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryBuilder\\:\\:add\\(\\)\\.$#"
count: 1
path: ../Classes/ViewHelpers/GetDatabaseRecordViewHelper.php
8 changes: 8 additions & 0 deletions Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/BackendPreviewRenderer.php
8 changes: 8 additions & 0 deletions Build/phpstan12.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan-baseline12.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/BackendPreviewRenderer.php
8 changes: 8 additions & 0 deletions Build/phpstan13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan-baseline13.neon
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/BackendPreviewRenderer.php
46 changes: 45 additions & 1 deletion Classes/Backend/Preview/ContentPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,56 @@
*/

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Core\Domain\RecordInterface;
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 TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;

class ContentPreview
{
public function render(array $row): ?string
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
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()
)
);
$view->assign('record', $record);
try {
return $view->render($fluidTemplateName);
} catch (InvalidTemplateResourceException) {
}
return null;
}

public function renderLegacy(array $row): ?string
{
$previewConfiguration = BackendUtility::getPagesTSconfig($row['pid'])['mod.']['web_layout.']['tt_content.']['preview.'] ?? [];
if (!$previewConfiguration) {
Expand Down
8 changes: 7 additions & 1 deletion Classes/Backend/Preview/StandardContentPreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Core\Domain\RecordInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class StandardContentPreviewRenderer extends \TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer
Expand All @@ -29,8 +30,13 @@ public function renderPageModulePreviewHeader(GridColumnItem $item): string
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$record = $item->getRecord();
$context = $item->getContext();
$contentPreview = GeneralUtility::makeInstance(ContentPreview::class);
$content = $contentPreview->render($record);
if ($record instanceof RecordInterface) {
$content = $contentPreview->render($record, $context);
} else {
$content = $contentPreview->renderLegacy($record);
}
if ($content !== null) {
return $content;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/BackendPreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function preProcess(
$row = $this->databaseRowService->extendRow($row);
if ((GeneralUtility::makeInstance(Features::class))->isFeatureEnabled('fluidBasedPageModule') === false) {
$contentPreview = GeneralUtility::makeInstance(ContentPreview::class);
$content = $contentPreview->render($row);
$content = $contentPreview->renderLegacy($row);
if ($content !== null) {
$itemContent .= $content;
$drawItem = false;
Expand Down
4 changes: 4 additions & 0 deletions Classes/Listener/PageContentPreviewRendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use B13\Backendpreviews\Service\DatabaseRowService;
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Core\Information\Typo3Version;

class PageContentPreviewRendering
{
Expand All @@ -26,6 +27,9 @@ public function __construct(DatabaseRowService $databaseRowService)

public function __invoke(PageContentPreviewRenderingEvent $event): void
{
if ((new Typo3Version())->getMajorVersion() > 13) {
return;
}
$record = $event->getRecord();
$record = $this->databaseRowService->extendRow($record);
$event->setRecord($record);
Expand Down
1 change: 1 addition & 0 deletions Classes/Service/DatabaseRowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\SingletonInterface;
Expand Down
8 changes: 2 additions & 6 deletions Classes/ViewHelpers/ExplodeListViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* of the License, or any later version.
*/

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;

/**
* Class ExplodeListViewHelper
Expand Down Expand Up @@ -47,9 +45,7 @@ public function initializeArguments(): void
$this->registerArgument(
'splitNL',
'boolean',
'Split newlines. If this is true, splitChar is ignored.',
'',
false
'Split newlines. If this is true, splitChar is ignored.'
);
}

Expand All @@ -60,7 +56,7 @@ public function render()
} else {
$splitChar = $this->arguments['splitChar'] ?? self::DEFAULT_SPLIT_CHAR;
}
$value = $this->arguments['value'] ?? $renderChildrenClosure();
$value = $this->arguments['value'] ?? $this->renderChildren();
return explode($splitChar, (string)$value);
}
}
6 changes: 2 additions & 4 deletions Classes/ViewHelpers/GetDatabaseRecordViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;

/**
* Class GetDatabaseRecordViewHelper
Expand Down Expand Up @@ -76,9 +74,9 @@ public function render(): array
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($uids, Connection::PARAM_INT_ARRAY))
);
if ((new Typo3Version())->getMajorVersion() > 12) {
$queryBuilder->getConcreteQueryBuilder()->addOrderBy('FIELD(uid,' . implode(',', $uids ) . ')');
$queryBuilder->getConcreteQueryBuilder()->addOrderBy('FIELD(uid,' . implode(',', $uids) . ')');
} else {
$queryBuilder->add('orderBy', 'FIELD(uid,' . implode(',', $uids ) . ')');
$queryBuilder->add('orderBy', 'FIELD(uid,' . implode(',', $uids) . ')');
}
return $queryBuilder
->executeQuery()
Expand Down
Loading