Skip to content

Commit

Permalink
[FEATURE] Add event PluginPreviewSummaryEvent
Browse files Browse the repository at this point in the history
Deprecate the hook
`$GLOBALS['TYPO3_CONF_VARS']['EXT']['news'][\GeorgRinger\News\Hooks\PluginPreviewRenderer::class]['extensionSummary']`
and provide an alternative event

Resolves: #2569
  • Loading branch information
georgringer committed Nov 20, 2024
1 parent dfdd02b commit 362da13
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
39 changes: 39 additions & 0 deletions Classes/Event/PluginPreviewRendererEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace GeorgRinger\News\Event;

use GeorgRinger\News\Controller\CategoryController;
use GeorgRinger\News\Hooks\PluginPreviewRenderer;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Extbase\Mvc\Request;

final class PluginPreviewRendererEvent
{

protected GridColumnItem $item;
protected PluginPreviewRenderer $pluginPreviewRenderer;

public function __construct(GridColumnItem $item, PluginPreviewRenderer $pluginPreviewRenderer)
{
$this->item = $item;
$this->pluginPreviewRenderer = $pluginPreviewRenderer;
}

public function getItem(): GridColumnItem
{
return $this->item;
}

public function getPluginPreviewRenderer(): PluginPreviewRenderer
{
return $this->pluginPreviewRenderer;
}

}
12 changes: 10 additions & 2 deletions Classes/Hooks/PluginPreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

namespace GeorgRinger\News\Hooks;

use GeorgRinger\News\Event\PluginPreviewRendererEvent;
use GeorgRinger\News\Utility\TemplateLayout;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Information\Typo3Version;
Expand Down Expand Up @@ -43,19 +46,21 @@ class PluginPreviewRenderer extends StandardContentPreviewRenderer
public array $flexformData = [];
protected IconFactory $iconFactory;
protected TemplateLayout $templateLayoutsUtility;
protected EventDispatcherInterface $eventDispatchter;
private int $pageId = 0;

public function __construct()
{
$this->templateLayoutsUtility = GeneralUtility::makeInstance(TemplateLayout::class);
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$this->eventDispatchter = GeneralUtility::makeInstance(EventDispatcher::class);
}

public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$this->pageId = $item->getContext()->getPageId();
$row = $item->getRecord();
$actionTranslationKey = $result = '';
$result = '';
$header = '<strong>' . htmlspecialchars($this->getLanguageService()->sL(self::LLPATH . 'pi1_title')) . '</strong>';
$this->tableData = [];
$flexforms = GeneralUtility::xml2array((string)$row['pi_flexform']);
Expand Down Expand Up @@ -112,14 +117,17 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$this->getTemplateLayoutSettings($row['pid']);
}

// @deprecated, use PluginPreviewRendererEvent instead
if ($hooks = $GLOBALS['TYPO3_CONF_VARS']['EXT']['news'][\GeorgRinger\News\Hooks\PluginPreviewRenderer::class]['extensionSummary'] ?? []) {
$params['action'] = $actionTranslationKey;
$params['item'] = $item;
foreach ($hooks as $reference) {
GeneralUtility::callUserFunction($reference, $params, $this);
}
}

$event = new PluginPreviewRendererEvent($item, $this);
$this->eventDispatchter->dispatch($event);

// for all views
$this->getOverrideDemandSettings();

Expand Down
1 change: 1 addition & 0 deletions Documentation/Reference/Events/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fired. For additional items see column "Access to" in the table below.
.. csv-table:: Events
:header: "Event class", "Fired in class", "Access to", "Old Signal"

"PluginPreviewRendererEvent", "PluginPreviewRenderer", "", ""
"NewsCheckPidOfNewsRecordFailedInDetailActionEvent", "NewsController", "getNews()", "checkPidOfNewsRecordFailedInDetailAction"
"NewsDateMenuActionEvent", "NewsController", "getAssignedValues()", "dateMenuAction (NewsController::SIGNAL_NEWS_DATEMENU_ACTION)"
"NewsDetailActionEvent", "NewsController", "getAssignedValues()", "detailAction (NewsController::SIGNAL_NEWS_DETAIL_ACTION)"
Expand Down

0 comments on commit 362da13

Please sign in to comment.