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
17 changes: 5 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
TYPO3: [ '11' , '12', '13', '14' ]
TYPO3: [ '12', '13', '14' ]

steps:
- name: Checkout
Expand Down Expand Up @@ -39,27 +39,20 @@ jobs:
- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer install --no-progress --no-interaction
composer require typo3/cms-core:^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 --no-progress --no-interaction --dev -W
- name: Install composer dependencies TYPO3 11
if: matrix.TYPO3 == '11'
run: |
composer require typo3/cms-core:^11.5 --no-progress --no-interaction --dev -W
- name: Phpstan 14
if: matrix.TYPO3 == '14'
run: .Build/bin/phpstan analyze -c Build/phpstan.neon
- 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
- name: Phpstan 11
if: matrix.TYPO3 == '11'
run: .Build/bin/phpstan analyze -c Build/phpstan11.neon
- name: Phpcsfix
run: .Build/bin/php-cs-fixer fix --config=Build/php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no
- name: Functional Tests
Expand Down
21 changes: 21 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parameters:
ignoreErrors:
-
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\\\\Listelements\\\\Service\\\\ListService\\:\\:resolveListitems\\(\\) expects array, TYPO3\\\\CMS\\\\Core\\\\Domain\\\\RecordInterface given\\.$#"
count: 1
path: ../Classes/Listener/PageContentPreviewRendering.php

-
message: "#^Call to an undefined method TYPO3\\\\CMS\\\\Core\\\\Domain\\\\Repository\\\\PageRepository\\:\\:enableFields\\(\\)\\.$#"
count: 1
path: ../Classes/Service/ListService.php

-
message: "#^Call to an undefined static method TYPO3\\\\CMS\\\\Core\\\\Versioning\\\\VersionState\\:\\:cast\\(\\)\\.$#"
count: 1
path: ../Classes/Service/ListService.php
2 changes: 1 addition & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon
- phpstan-baseline.neon
parameters:
level: 5
paths:
Expand Down
2 changes: 0 additions & 2 deletions Build/phpstan11.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
includes:
- ../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon
parameters:
level: 5
paths:
Expand Down
2 changes: 0 additions & 2 deletions Build/phpstan12.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
includes:
- ../.Build/vendor/saschaegerer/phpstan-typo3/extension.neon
parameters:
level: 5
paths:
Expand Down
6 changes: 6 additions & 0 deletions Build/phpstan13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 5
paths:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Hooks/DrawItem.php
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\Listelements\Service\ListService;
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Core\Information\Typo3Version;

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

public function __invoke(PageContentPreviewRenderingEvent $event): void
{
if ((new Typo3Version())->getMajorVersion() > 13) {
return;
}
$record = $event->getRecord();
if ($record['tx_listelements_list'] ?? false) {
$record = $this->listService->resolveListitems($record);
Expand Down
10 changes: 6 additions & 4 deletions Classes/Service/ListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ListService implements SingletonInterface
*/
public function resolveListitems(array $row, string $field = 'tx_listelements_list', string $table = 'tt_content', string $filereferences = 'assets,images'): array
{
// used for BE in TYPO3 < 14
$returnAs = 'listitems_' . $field;
if ($returnAs === 'listitems_tx_listelements_list') {
$returnAs = 'listitems';
Expand Down Expand Up @@ -96,11 +97,12 @@ public function resolveItemsForFrontend(int $uid, string $table = 'tt_content',
$constraints = $pageRepository->getDefaultConstraints(self::TABLE);
if ($constraints === []) {
$additionalWhere = '';
} else {
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table)
->expr();
$additionalWhere = ' AND ' . $expressionBuilder->and(...$constraints);
}
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table)
->expr();
$additionalWhere = ' AND ' . $expressionBuilder->and(...$constraints);
}
$relationHandler->additionalWhere[self::TABLE] = $additionalWhere;
$relationHandler->start(
Expand Down
79 changes: 40 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,49 @@ content element's Fluid template, like this:

## Backend PageLayoutView preview

This extension adds a Hook and a Service class to allow customized display using Fluid templates for the backend Page
Layout View. Use this to add customized preview data if you add additional assets/image fields to be resolved for
backend preview:
This extension adds a PageContentPreviewRendering Listener to resolve ListItems (and if needed further Relations to asses/images) to allow customized display using Fluid templates for the backend Page
Layout View.

`EXT:site_extension/Classes/Hooks/DrawItem.php`:
For TYPO3 Version > 12 the Listener is not required anymore, because TYPO3 use the Record Api to resolve relations automatically.

For TYPO3 Version > 13 the Listener is not used anymore (because the Event changed)

s. https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/14.0/Breaking-92434-UseRecordAPIInPageModulePreviewRendering.html

Migrate or BE-Templates

old:

```html
<ul>
<f:for each="{listitems}" as="item">
<li>
{item.header}
<f:if condition="{item.processedImages}">
<f:for each="{item.processedImages}" as="image">
<f:image src="{image.uid}" treatIdAsReference="true"/>
</f:for>
</f:if>
</li>
</f:for>
</ul>
```
<?php

namespace B13\SiteExtension\Hooks;

use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Backend\View\PageLayoutView;

/**
* Class/Function to manipulate the rendering of item preview content
*
*/
class DrawItem implements PageLayoutViewDrawItemHookInterface
{

/**
* @param PageLayoutView $parentObject : The parent object that triggered this hook
* @param boolean $drawItem : A switch to tell the parent object, if the item still must be drawn
* @param string $headerContent : The content of the item header
* @param string $itemContent : The content of the item itself
* @param array $row : The current data row for this item
*
* @return void
*/
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
{

// get all list items (database column 'test_list') including all assets
if ($row['test_list']) {
// array &$row, $field = '', $table = 'tt_content', $filereferences = 'assets, additional_assets'
\B13\Listelements\Service\ListService::resolveListitems($row, 'test_list', 'tt_content');
}

}

}

new:

```html
<ul>
<f:for each="{record.tx_listelements_list}" as="item">
<li>
{item.header}
<f:if condition="{item.images}">
<f:for each="{item.images}" as="image">
<f:image src="{image.uid}" treatIdAsReference="true"/>
</f:for>
</f:if>
</li>
</f:for>
</ul>
```

## Important info on configuration
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"typo3/testing-framework": "^7.0 || ^8.0",
"typo3/testing-framework": "^7.0 || ^8.0 || ^9.1",
"typo3/cms-frontend": "^11.5 || ^12.4 || ^13.1 || ^14.0",
"typo3/cms-workspaces": "^11.5 || ^12.4 || ^13.1 || ^14.0",
"saschaegerer/phpstan-typo3": "^1.8",
"phpstan/phpstan": "^1.10",
"typo3/coding-standards": "^0.5.5",
"phpunit/phpunit": "9.6 || ^10.5 || ^11.3",
"b13/listelements-example": "*"
},
"autoload-dev": {
Expand Down