Skip to content

Commit

Permalink
[FEATURE] Add close button with returnUrl in page layout module
Browse files Browse the repository at this point in the history
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 committed Apr 15, 2024
1 parent bc43c31 commit 5a75128
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 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\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

Expand Down Expand Up @@ -55,4 +59,31 @@ protected function generateMessagesForCurrentPage(): string

return $content;
}


/**
* @param ServerRequestInterface $request
* @return void
*
* credit: based on Stack Overflow answer https://stackoverflow.com/a/78319234/2444812
* by Mogens https://stackoverflow.com/users/5023204/mogens
*/
protected function makeButtons(ServerRequestInterface $request): void
{
parent::makeButtons($request);

$returnUrl = $request->getQueryParams()['returnUrl'] ?? '';
if (!$returnUrl) {
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);
}
}

0 comments on commit 5a75128

Please sign in to comment.