Skip to content

Commit

Permalink
[TASK] Re-implement page header preview as PSR-14 event
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Aug 2, 2023
1 parent 9aa5963 commit aee4987
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
58 changes: 58 additions & 0 deletions Classes/Integration/Event/ModifyPageLayoutContentEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace FluidTYPO3\Flux\Integration\Event;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Integration\PreviewRenderer;
use FluidTYPO3\Flux\Integration\PreviewView;
use FluidTYPO3\Flux\Provider\PageProvider;
use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ModifyPageLayoutContentEventListener
{
private PageProvider $pageProvider;

public function __construct(PageProvider $pageProvider)
{
$this->pageProvider = $pageProvider;
}

public function renderPreview(ModifyPageLayoutContentEvent $event): void
{
$id = $event->getRequest()->getQueryParams()['id'] ?? 0;

$row = $this->getRecord(is_scalar($id) ? (integer) $id : 0);
if ($row === null) {
return;
}

$form = $this->pageProvider->getForm($row);
if (!$form || !$form->getEnabled()) {
return;
}

// Force the preview to *not* generate content column HTML in preview
$form->setOption(PreviewView::OPTION_PREVIEW, [
PreviewView::OPTION_MODE => PreviewView::MODE_NONE
]);

[, $previewContent, ] = $this->pageProvider->getPreview($row);
$event->setHeaderContent($previewContent);
}

/**
* @codeCoverageIgnore
*/
protected function getRecord(int $uid): ?array
{
return BackendUtility::getRecord('pages', $uid);
}
}
7 changes: 7 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ services:
FluidTYPO3\Flux\Form\Transformation\FormDataTransformer:
public: true

FluidTYPO3\Flux\Integration\Event\ModifyPageLayoutContentEventListener:
public: true
tags:
- name: event.listener
identifier: 'flux-page-preview'
method: 'renderPreview'
event: TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent
FluidTYPO3\Flux\Integration\Event\PageContentPreviewRenderingEventListener:
tags:
- name: event.listener
Expand Down
5 changes: 4 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
);

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['BackendLayoutDataProvider']['flux'] = \FluidTYPO3\Flux\Backend\BackendLayoutDataProvider::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] = \FluidTYPO3\Flux\Integration\HookSubscribers\PagePreviewRenderer::class . '->render';

if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '12', '<')) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'][] = \FluidTYPO3\Flux\Integration\HookSubscribers\PagePreviewRenderer::class . '->render';
}

$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] .= ($GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] == '' ? '' : ',') .
'tx_fed_page_controller_action,tx_fed_page_controller_action_sub,tx_fed_page_flexform,tx_fed_page_flexform_sub,';
Expand Down

0 comments on commit aee4987

Please sign in to comment.