diff --git a/typo3/sysext/backend/Classes/Controller/Event/AfterPageColumnsSelectedForLocalizationEvent.php b/typo3/sysext/backend/Classes/Controller/Event/AfterPageColumnsSelectedForLocalizationEvent.php new file mode 100644 index 0000000000000000000000000000000000000000..ca61790259b70c723242223e89310d001664722a --- /dev/null +++ b/typo3/sysext/backend/Classes/Controller/Event/AfterPageColumnsSelectedForLocalizationEvent.php @@ -0,0 +1,108 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Backend\Controller\Event; + +use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout; + +/** + * This event triggers after the LocalizationController (AJAX) has + * selected page columns to be translated. Allows third parties to + * add to or change the columns and content elements withing those + * columns which will be available for localization through the + * "translate" modal in the page module. + */ +final class AfterPageColumnsSelectedForLocalizationEvent +{ + /** + * List of columns, indexed by column position number, value is label (either LLL: or hardcoded). + * + * @var array + */ + private $columns; + + /** + * Array of records which were used when building the original column + * manifest and column position numbers list. + * + * @var array + */ + private $records; + + /** + * Request parameters passed to LocalizationController. + * + * @var array + */ + private $parameters; + + /** + * @var BackendLayout + */ + private $backendLayout; + + /** + * List of integer column position numbers used in the BackendLayout. + * + * @var array + */ + private $columnList; + + public function __construct(array $columns, array $columnList, BackendLayout $backendLayout, array $records, array $parameters) + { + $this->columns = $columns; + $this->columnList = $columnList; + $this->backendLayout = $backendLayout; + $this->records = $records; + $this->parameters = $parameters; + } + + public function getColumns(): array + { + return $this->columns; + } + + public function setColumns(array $columns): void + { + $this->columns = $columns; + } + + public function getColumnList(): array + { + return $this->columnList; + } + + public function setColumnList(array $columnList): void + { + $this->columnList = $columnList; + } + + public function getBackendLayout(): BackendLayout + { + return $this->backendLayout; + } + + public function getRecords(): array + { + return $this->records; + } + + public function getParameters(): array + { + return $this->parameters; + } +} diff --git a/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php b/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php index e669334dc2ba948d4c81a161b4815ae2ad2aafd1..5b04784668efbfea47d752c2b0ae6edfcdbd64c1 100644 --- a/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php +++ b/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php @@ -17,9 +17,11 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\Controller\Page; +use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider; +use TYPO3\CMS\Backend\Controller\Event\AfterPageColumnsSelectedForLocalizationEvent; use TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendLayoutView; @@ -58,6 +60,11 @@ class LocalizationController */ protected $localizationRepository; + /** + * @var EventDispatcherInterface + */ + protected $eventDispatcher; + /** * Constructor */ @@ -65,6 +72,7 @@ class LocalizationController { $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); $this->localizationRepository = GeneralUtility::makeInstance(LocalizationRepository::class); + $this->eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class); } /** @@ -141,6 +149,7 @@ class LocalizationController '*' ); + $flatRecords = []; while ($row = $result->fetch()) { BackendUtility::workspaceOL('tt_content', $row, -99, true); if (!$row || VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) { @@ -155,11 +164,12 @@ class LocalizationController 'title' => $row[$GLOBALS['TCA']['tt_content']['ctrl']['label']], 'uid' => $row['uid'] ]; + $flatRecords[] = $row; } return (new JsonResponse())->setPayload([ 'records' => $records, - 'columns' => $this->getPageColumns($pageId), + 'columns' => $this->getPageColumns($pageId, $flatRecords, $params), ]); } @@ -255,9 +265,11 @@ class LocalizationController /** * @param int $pageId + * @param array $flatRecords + * @param array $params * @return array */ - protected function getPageColumns(int $pageId): array + protected function getPageColumns(int $pageId, array $flatRecords, array $params): array { $columns = []; $backendLayoutView = GeneralUtility::makeInstance(BackendLayoutView::class); @@ -267,9 +279,12 @@ class LocalizationController $columns[$columnPos] = $GLOBALS['LANG']->sL($columnLabel); } + $event = GeneralUtility::makeInstance(AfterPageColumnsSelectedForLocalizationEvent::class, $columns, array_values($backendLayout->getColumnPositionNumbers()), $backendLayout, $flatRecords, $params); + $this->eventDispatcher->dispatch($event); + return [ - 'columns' => $columns, - 'columnList' => array_values($backendLayout->getColumnPositionNumbers()), + 'columns' => $event->getColumns(), + 'columnList' => $event->getColumnList() ]; } } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-90945-PSR-14EventForLocalizationControllerWhenReadingRecordscolumnsToBeTranslated.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-90945-PSR-14EventForLocalizationControllerWhenReadingRecordscolumnsToBeTranslated.rst new file mode 100644 index 0000000000000000000000000000000000000000..01e7b96f4fba93e7f0699a3d85adc33b640100d5 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-90945-PSR-14EventForLocalizationControllerWhenReadingRecordscolumnsToBeTranslated.rst @@ -0,0 +1,33 @@ +.. include:: ../../Includes.txt + +======================================================================================================= +Feature: #90945 - PSR-14 event for LocalizationController when reading records/columns to be translated +======================================================================================================= + +See :issue:`90945` + +Description +=========== + +A new PSR-14 event ``\TYPO3\CMS\Backend\Controller\Event\AfterPageColumnsSelectedForLocalizationEvent`` +has been added and will be dispatched after records and columns are collected in the ``LocalizationController``. + +The event receives: + +* The default columns and columnsList built by ``LocalizationController``. +* The list of records that were analyzed to create the columns manifest. +* The parameters received by the ``LocalizationController``. + +The event allows changes to: + +* The columns and the columnsList. + + +Impact +====== + +This allows third party code to read or manipulate the "columns manifest" that gets displayed in the +translation modal when a user has clicked the "Translate" button in the page module, by implementing +a listener for the ``\TYPO3\CMS\Backend\Controller\Event\AfterPageColumnsSelectedForLocalizationEvent`` event. + +.. index:: Backend, ext:backend