From 77d9c0856d02d85c0a403ecc9832333d39c36f35 Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Mon, 15 Apr 2024 14:55:11 +0200 Subject: [PATCH] [FEATURE] Add close button with returnUrl in page layout module (#25) * [FEATURE] Add close button with returnUrl in page layout module Show close button in page layout view if query parameter returnUrl is set. This can then be used in EXT:brofix (and other extensions) to pass the returnUrl and the user can jump back by clicking the close button. Resolves: #22 --- .../PageLayoutControllerWithCallouts.php | 41 +++++++++++++++++++ .../Entries/3.x/Feature-ShowCloseButton.rst | 14 +++++++ ext_conf_template.txt | 6 +++ ext_emconf.php | 2 +- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Documentation/Changelog/Entries/3.x/Feature-ShowCloseButton.rst create mode 100644 ext_conf_template.txt diff --git a/Classes/Xclass/PageLayoutControllerWithCallouts.php b/Classes/Xclass/PageLayoutControllerWithCallouts.php index bf905fa..2d204ce 100644 --- a/Classes/Xclass/PageLayoutControllerWithCallouts.php +++ b/Classes/Xclass/PageLayoutControllerWithCallouts.php @@ -16,7 +16,11 @@ * The TYPO3 project - inspiring people to share! */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Backend\Controller\PageLayoutController; +use TYPO3\CMS\Backend\Template\Components\ButtonBar; +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\View\StandaloneView; @@ -55,4 +59,41 @@ protected function generateMessagesForCurrentPage(): string return $content; } + + /** + * @param ServerRequestInterface $request + */ + protected function makeButtons(ServerRequestInterface $request): void + { + parent::makeButtons($request); + + $returnUrl = $request->getQueryParams()['returnUrl'] ?? ''; + if (!$returnUrl) { + return; + } + + // check if enabled in Extension Configuration + if (!$this->getExtensionConfigurationTypeBool('enableCloseButtonInPageModule', true)) { + return; + } + + $returnButton = $this->buttonBar->makeLinkButton() + ->setHref($returnUrl) + ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.close') ?: 'Close') + // Create your custom icon or use any of the alredy created icons + ->setIcon($this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)) + ->setShowLabelText(true); + // should use BUTTON_POSITION_RIGHT, but does not work? + $this->buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 0); + } + + protected function getExtensionConfigurationTypeBool(string $setting, bool $defaultValue): bool + { + /** @var array $extConf */ + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('page_callouts'); + if (isset($extConf[$setting])) { + return (bool)$extConf[$setting]; + } + return $defaultValue; + } } diff --git a/Documentation/Changelog/Entries/3.x/Feature-ShowCloseButton.rst b/Documentation/Changelog/Entries/3.x/Feature-ShowCloseButton.rst new file mode 100644 index 0000000..09315c4 --- /dev/null +++ b/Documentation/Changelog/Entries/3.x/Feature-ShowCloseButton.rst @@ -0,0 +1,14 @@ +.. include:: /Includes.rst.txt + +=========================== +Feature - Show close button +=========================== + +If the page module is opened with a parameter "returnUrl", a close button is +displaye and we jump to the URL if the module is closed via this button. + +Migration +========= + +No migration necessary. If you do not want this behaviour, disable it in the +extension configuration (enableCloseButtonInPageModule). diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..7926043 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,6 @@ +### separate label and description with ":" +### Things added in later versions, add at the bottom + +# cat=enable; type=bool; label=Enable close button in page module if returnUrl is set +enableCloseButtonInPageModule = 1 + diff --git a/ext_emconf.php b/ext_emconf.php index f0081e5..37d7960 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -11,7 +11,7 @@ 'uploadfolder' => 0, 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '3.0.3-dev', + 'version' => '3.1.0-dev', 'constraints' => [ 'depends' => [ 'typo3' => '11.5.30-11.5.99',