From 4261350d1c0206a4abcd6258412d2656178af6e1 Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Tue, 12 Nov 2024 09:58:35 +0100 Subject: [PATCH 1/8] [FEATURE] Add event for editing module template Relates: https://projekte.in2code.de/issues/67976 --- .../Traits/ControllerModuleTemplate.php | 12 ++++ .../ModuleTemplateWasPreparedForRendering.php | 65 +++++++++++++++++++ .../ModuleTemplateWasPreparedForRendering.md | 38 +++++++++++ 3 files changed, 115 insertions(+) create mode 100644 Classes/Event/ModuleTemplateWasPreparedForRendering.php create mode 100644 Documentation/Developers/Events/ModuleTemplateWasPreparedForRendering.md diff --git a/Classes/Controller/Traits/ControllerModuleTemplate.php b/Classes/Controller/Traits/ControllerModuleTemplate.php index 8e974e663..1479f2d54 100644 --- a/Classes/Controller/Traits/ControllerModuleTemplate.php +++ b/Classes/Controller/Traits/ControllerModuleTemplate.php @@ -31,6 +31,8 @@ use In2code\In2publishCore\Backend\Button\ModuleShortcutButton; use In2code\In2publishCore\CommonInjection\ModuleTemplateFactoryInjection; +use In2code\In2publishCore\Event\ModuleTemplateWasPreparedForRendering; +use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Template\ModuleTemplate; @@ -43,6 +45,8 @@ /** * @property Request $request + * @property EventDispatcherInterface $eventDispatcher + * @property string $actionMethodName */ trait ControllerModuleTemplate { @@ -84,6 +88,14 @@ protected function render(): string $buttonBar->addButton($moduleShortcutButton); $this->moduleTemplate->setContent($this->view->render()); + + $event = new ModuleTemplateWasPreparedForRendering( + $this->moduleTemplate, + static::class, + $this->actionMethodName + ); + $this->eventDispatcher->dispatch($event); + return $this->moduleTemplate->renderContent(); } } diff --git a/Classes/Event/ModuleTemplateWasPreparedForRendering.php b/Classes/Event/ModuleTemplateWasPreparedForRendering.php new file mode 100644 index 000000000..2ad8d6361 --- /dev/null +++ b/Classes/Event/ModuleTemplateWasPreparedForRendering.php @@ -0,0 +1,65 @@ + + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + */ + +namespace In2code\In2publishCore\Event; + +use TYPO3\CMS\Backend\Template\ModuleTemplate; + +final class ModuleTemplateWasPreparedForRendering +{ + private ModuleTemplate $moduleTemplate; + private string $controllerClass; + private string $actionMethodName; + + public function __construct( + ModuleTemplate $moduleTemplate, + string $controllerClass, + string $actionMethodName) + { + $this->moduleTemplate = $moduleTemplate; + $this->controllerClass = $controllerClass; + $this->actionMethodName = $actionMethodName; + } + + public function getModuleTemplate(): ModuleTemplate + { + return $this->moduleTemplate; + } + + public function getControllerClass(): string + { + return $this->controllerClass; + } + + public function getActionMethodName(): string + { + return $this->actionMethodName; + } + +} diff --git a/Documentation/Developers/Events/ModuleTemplateWasPreparedForRendering.md b/Documentation/Developers/Events/ModuleTemplateWasPreparedForRendering.md new file mode 100644 index 000000000..8e31abe03 --- /dev/null +++ b/Documentation/Developers/Events/ModuleTemplateWasPreparedForRendering.md @@ -0,0 +1,38 @@ +# ModuleTemplateWasPreparedForRendering + +## When + +This event is fired each time a backend module is opened. + +## What + +* `moduleTemplate`: an object of type TYPO3\CMS\Backend\Template\ModuleTemplate +* `controllerClass`: controller class calling the event +* `actionMethodName`: action method name calling the event + +## Possibilities + +With this event you can add e.g. buttons to the docheader of a backend module. + +### Example + +This example shows you how to add a button to the docheader of the redirect module. + +```php +use In2code\In2publish\Features\ContentLanguageControl\Toolbar\LanguageSelectionButtonInjection; +use In2code\In2publishCore\Event\ModuleTemplateWasPreparedForRendering; +use In2code\In2publishCore\Features\RedirectsSupport\Controller\RedirectController; + +class ModuleTemplateButtonBarSelectionRenderer +{ + use LanguageSelectionButtonInjection; + + public function whenModuleTemplateWasPreparedForRendering(ModuleTemplateWasPreparedForRendering $event): void + { + if (RedirectController::class === $event->getControllerClass() && 'listAction' === $event->getActionMethodName()){ + $moduleTemplate = $event->getModuleTemplate(); + $moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($this->languageSelectionButton); + } + } +} +``` From 0acabf2a5fcd4c0dcb6901025f5c6d98831e0cad Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Tue, 12 Nov 2024 13:12:16 +0100 Subject: [PATCH 2/8] [FEATURE] Add event for filtering redirects in redirects module Relates: https://projekte.in2code.de/issues/67976 --- .../Controller/RedirectController.php | 7 ++- .../Event/RedirectsWereFilteredForListing.php | 50 +++++++++++++++++++ .../Events/RedirectsWereFilteredForListing.md | 44 ++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Classes/Features/RedirectsSupport/Event/RedirectsWereFilteredForListing.php create mode 100644 Documentation/Developers/Events/RedirectsWereFilteredForListing.md diff --git a/Classes/Features/RedirectsSupport/Controller/RedirectController.php b/Classes/Features/RedirectsSupport/Controller/RedirectController.php index e4a0d1648..10a185546 100644 --- a/Classes/Features/RedirectsSupport/Controller/RedirectController.php +++ b/Classes/Features/RedirectsSupport/Controller/RedirectController.php @@ -46,6 +46,7 @@ use In2code\In2publishCore\Features\RedirectsSupport\Domain\Dto\Filter; use In2code\In2publishCore\Features\RedirectsSupport\Domain\Model\SysRedirectDatabaseRecord; use In2code\In2publishCore\Features\RedirectsSupport\Domain\Repository\SysRedirectRepository; +use In2code\In2publishCore\Features\RedirectsSupport\Event\RedirectsWereFilteredForListing; use In2code\In2publishCore\Service\ForeignSiteFinderInjection; use Psr\Http\Message\ResponseInterface; use Throwable; @@ -154,7 +155,11 @@ public function listAction(Filter $filter = null, int $page = 1): ResponseInterf $this->demandResolver->resolveDemand($demands, $recordCollection); $redirects = $this->getRedirectsByStateFromFilter($recordTree, $filter); - $paginator = new ArrayPaginator($redirects, $page, 15); + + $event = new RedirectsWereFilteredForListing($redirects); + $this->eventDispatcher->dispatch($event); + + $paginator = new ArrayPaginator($event->getRedirects(), $page, 15); $pagination = new SimplePagination($paginator); $this->view->assignMultiple( [ diff --git a/Classes/Features/RedirectsSupport/Event/RedirectsWereFilteredForListing.php b/Classes/Features/RedirectsSupport/Event/RedirectsWereFilteredForListing.php new file mode 100644 index 000000000..3116f7d52 --- /dev/null +++ b/Classes/Features/RedirectsSupport/Event/RedirectsWereFilteredForListing.php @@ -0,0 +1,50 @@ + + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + */ + +namespace In2code\In2publishCore\Features\RedirectsSupport\Event; + +final class RedirectsWereFilteredForListing +{ + private array $redirects; + + public function __construct(array $redirects) + { + $this->redirects = $redirects; + } + + public function getRedirects(): array + { + return $this->redirects; + } + + public function setRedirects(array $redirects): void + { + $this->redirects = $redirects; + } +} diff --git a/Documentation/Developers/Events/RedirectsWereFilteredForListing.md b/Documentation/Developers/Events/RedirectsWereFilteredForListing.md new file mode 100644 index 000000000..c986e8533 --- /dev/null +++ b/Documentation/Developers/Events/RedirectsWereFilteredForListing.md @@ -0,0 +1,44 @@ +# RedirectsWereFilteredForListing + +## When + +The event is fired after the redirects are filtered for display in the listAction of the RedirectController. + +## What + +* `redirects`: an array of SysRedirectDatabaseRecord + +## Possibilities + +With this event you can filter the records in more detail on your own. + +### Example + +This example show how to filter the redirects with the Language Uid of the Parent Page. + +```php +class FilterRedirectsBySelectedLanguages +{ + use UserSelectionServiceInjection; + use RawRecordServiceInjection; + + public function __invoke(RedirectsWereFilteredForListing $event): void + { + $redirects = $event->getRedirects(); + $selectedLanguages = [-1,0,4]; + + $redirects = array_filter($redirects, function (SysRedirectDatabaseRecord $redirect) use ($selectedLanguages) { + $pid = (int)$redirect->getLocalProps()['pid']; + if (0 === $pid) { + return true; + } + $record = $this->rawRecordService->getRawRecord('pages', $pid, 'local'); + if (in_array($record['sys_language_uid'], $selectedLanguages)){ + return true; + } + }); + + $event->setRedirects($redirects); + } +} +``` From 9e0877e25bf7c6706806bfe486df123901d043d5 Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Tue, 19 Nov 2024 14:25:10 +0100 Subject: [PATCH 3/8] [FEATURE] Add Reasons Modal to Redirects Relates: https://projekte.in2code.de/issues/67976 --- .../ShowReasonsButtonViewHelper.php | 78 +++++++++++++++++++ .../Private/Language/de.locallang_mod5.xlf | 4 + Resources/Private/Language/locallang_mod5.xlf | 3 + .../Private/Templates/Redirect/List.html | 60 ++++++++------ 4 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php diff --git a/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php b/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php new file mode 100644 index 000000000..90e9327a8 --- /dev/null +++ b/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php @@ -0,0 +1,78 @@ + + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + */ + +use In2code\In2publishCore\CommonInjection\TranslationConfigurationProviderInjection; +use In2code\In2publishCore\Features\RedirectsSupport\Domain\Model\SysRedirectDatabaseRecord; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; + +class ShowReasonsButtonViewHelper extends AbstractTagBasedViewHelper +{ + + + protected $tagName = 'a'; + + public function initializeArguments(): void + { + parent::initializeArguments(); + $this->registerUniversalTagAttributes(); + $this->registerArgument('redirectRecord', SysRedirectDatabaseRecord::class, '', true); + } + + public function render() : string + { + /** + * @var $redirectRecord SysRedirectDatabaseRecord + */ + $redirectRecord = $this->arguments['redirectRecord']; + $this->tag->addAttribute('href','#'); + $this->tag->setContent($this->renderChildren()); + $modalConfiguration = [ + 'settings' => [ + 'title' => LocalizationUtility::translate('LLL:EXT:in2publish_core/Resources/Private/Language/locallang_mod5.xlf:modal.reasons.title'), + 'content' => implode("\r\n", $redirectRecord->getReasonsWhyTheRecordIsNotPublishableHumanReadable()), + 'severity' => 1, + ], + 'buttons' => [ + 'abort' => [ + 'text' => 'Abort', + 'btnClass' => 'btn btn-default', + 'name' => 'abort', + 'active' => true, + ] + ] + ]; + $this->tag->addAttribute('data-modal-configuration', json_encode($modalConfiguration)); + + return $this->tag->render(); + } +} diff --git a/Resources/Private/Language/de.locallang_mod5.xlf b/Resources/Private/Language/de.locallang_mod5.xlf index 2afeaf36d..40889ccca 100755 --- a/Resources/Private/Language/de.locallang_mod5.xlf +++ b/Resources/Private/Language/de.locallang_mod5.xlf @@ -15,6 +15,10 @@ TYPO3 Content Publisher - Redirects TYPO3 Content Publisher - Redirects + + Redirect is not publishable + Redirect kann nicht publiziert werden. + diff --git a/Resources/Private/Language/locallang_mod5.xlf b/Resources/Private/Language/locallang_mod5.xlf index 00d2dbad2..6478faa51 100755 --- a/Resources/Private/Language/locallang_mod5.xlf +++ b/Resources/Private/Language/locallang_mod5.xlf @@ -12,6 +12,9 @@ TYPO3 Content Publisher - Redirects + + Redirect is not publishable + diff --git a/Resources/Private/Templates/Redirect/List.html b/Resources/Private/Templates/Redirect/List.html index 5bee90836..95ec37ccc 100644 --- a/Resources/Private/Templates/Redirect/List.html +++ b/Resources/Private/Templates/Redirect/List.html @@ -1,6 +1,7 @@ @@ -65,30 +66,41 @@

- - -
- - - - -
-
- - - - - - - - - - -
+ + + + + + + + + +
+ + + + +
+
+ + + + + + + + + + +
+
+
From 03c13172d110572ba90f3283ec6e222bac6101eb Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Tue, 19 Nov 2024 14:30:46 +0100 Subject: [PATCH 4/8] [CODESTYLE] Fix Codestyle - Remove unused import - Remove empty lines - Change Line Breaks --- .../Core/Repository/SingleDatabaseRepository.php | 6 ++---- .../Event/ModuleTemplateWasPreparedForRendering.php | 5 ++--- .../ViewHelpers/ShowReasonsButtonViewHelper.php | 12 ++++-------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Classes/Component/Core/Repository/SingleDatabaseRepository.php b/Classes/Component/Core/Repository/SingleDatabaseRepository.php index 6f2d499fb..7e8226692 100644 --- a/Classes/Component/Core/Repository/SingleDatabaseRepository.php +++ b/Classes/Component/Core/Repository/SingleDatabaseRepository.php @@ -148,12 +148,10 @@ public function findByPropertyWithJoin( $splitRow['mmtbl']['uid_local'], $splitRow['mmtbl']['uid_foreign'], ]; - if(isset($splitRow['mmtbl']['tablenames'])) - { + if (isset($splitRow['mmtbl']['tablenames'])) { $mmIdentityProperties[] = $splitRow['mmtbl']['tablenames']; } - if(isset($splitRow['mmtbl']['fieldname'])) - { + if (isset($splitRow['mmtbl']['fieldname'])) { $mmIdentityProperties[] = $splitRow['mmtbl']['fieldname']; } $splitRows[hash('sha1', json_encode($mmIdentityProperties, JSON_THROW_ON_ERROR))] = $splitRow; diff --git a/Classes/Event/ModuleTemplateWasPreparedForRendering.php b/Classes/Event/ModuleTemplateWasPreparedForRendering.php index 2ad8d6361..29ee1bf86 100644 --- a/Classes/Event/ModuleTemplateWasPreparedForRendering.php +++ b/Classes/Event/ModuleTemplateWasPreparedForRendering.php @@ -40,8 +40,8 @@ final class ModuleTemplateWasPreparedForRendering public function __construct( ModuleTemplate $moduleTemplate, string $controllerClass, - string $actionMethodName) - { + string $actionMethodName + ) { $this->moduleTemplate = $moduleTemplate; $this->controllerClass = $controllerClass; $this->actionMethodName = $actionMethodName; @@ -61,5 +61,4 @@ public function getActionMethodName(): string { return $this->actionMethodName; } - } diff --git a/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php b/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php index 90e9327a8..ff49712c8 100644 --- a/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php +++ b/Classes/Features/RedirectsSupport/ViewHelpers/ShowReasonsButtonViewHelper.php @@ -29,16 +29,12 @@ * This copyright notice MUST APPEAR in all copies of the script! */ -use In2code\In2publishCore\CommonInjection\TranslationConfigurationProviderInjection; use In2code\In2publishCore\Features\RedirectsSupport\Domain\Model\SysRedirectDatabaseRecord; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; class ShowReasonsButtonViewHelper extends AbstractTagBasedViewHelper { - - protected $tagName = 'a'; public function initializeArguments(): void @@ -48,13 +44,13 @@ public function initializeArguments(): void $this->registerArgument('redirectRecord', SysRedirectDatabaseRecord::class, '', true); } - public function render() : string + public function render(): string { /** * @var $redirectRecord SysRedirectDatabaseRecord */ $redirectRecord = $this->arguments['redirectRecord']; - $this->tag->addAttribute('href','#'); + $this->tag->addAttribute('href', '#'); $this->tag->setContent($this->renderChildren()); $modalConfiguration = [ 'settings' => [ @@ -68,8 +64,8 @@ public function render() : string 'btnClass' => 'btn btn-default', 'name' => 'abort', 'active' => true, - ] - ] + ], + ], ]; $this->tag->addAttribute('data-modal-configuration', json_encode($modalConfiguration)); From 1e41968b0f8bce5e684f3c22caba9faf151ccd10 Mon Sep 17 00:00:00 2001 From: Daniel Hoffmann Date: Thu, 21 Nov 2024 12:55:10 +0100 Subject: [PATCH 5/8] [BUGFIX] respect unchanged redirect Relates: https://projekte.in2code.de/issues/62544 --- Resources/Private/Templates/Redirect/List.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Private/Templates/Redirect/List.html b/Resources/Private/Templates/Redirect/List.html index 95ec37ccc..01d57dc2a 100644 --- a/Resources/Private/Templates/Redirect/List.html +++ b/Resources/Private/Templates/Redirect/List.html @@ -66,7 +66,7 @@

- +