forked from FluidTYPO3/flux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Re-implement page header preview as PSR-14 event
Close: FluidTYPO3#2111
- Loading branch information
1 parent
9aa5963
commit aee4987
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Classes/Integration/Event/ModifyPageLayoutContentEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters