Skip to content

Commit

Permalink
[FEATURE] Add close button with returnUrl in page layout module (#25)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
sypets authored Apr 15, 2024
1 parent 5e0f916 commit 77d9c08
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Classes/Xclass/PageLayoutControllerWithCallouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<string,mixed> $extConf */
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('page_callouts');
if (isset($extConf[$setting])) {
return (bool)$extConf[$setting];
}
return $defaultValue;
}
}
14 changes: 14 additions & 0 deletions Documentation/Changelog/Entries/3.x/Feature-ShowCloseButton.rst
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 6 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 77d9c08

Please sign in to comment.