From e217fbaf6701471a3de459adf74716dd3eb058dd Mon Sep 17 00:00:00 2001 From: Michael Oehlhof <typo3@oehlhof.de> Date: Wed, 14 Oct 2015 21:45:16 +0200 Subject: [PATCH] [TASK] Add new property displayName to ShortcutButton Actually the ShortcutButton shows the module name as label for a shortcut. For modules with different actions inside the module this results with the same label for all actions of a module. This patch add a new property displayName to the ShortcutButton. With this patch the label in the bookmark list can be set when creating the ShortcutButton using the new property displayName. If displayName is set it is used as label for the bookmark, if displayName is not set (empty) the ShortcutButton works as before. Resolves: #70698 Releases: master Change-Id: Ie650d08793f323581ebee52af59c32a8a85b08c9 Reviewed-on: https://review.typo3.org/44065 Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> --- .../ToolbarItems/ShortcutToolbarItem.php | 5 +++ .../Buttons/Action/ShortcutButton.php | 37 ++++++++++++++++--- .../Classes/Template/ModuleTemplate.php | 12 ++++-- .../Public/JavaScript/Toolbar/ShortcutMenu.js | 5 ++- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php index 01896ba6f404..b1ff716b93ce 100644 --- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php +++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php @@ -543,6 +543,11 @@ class ShortcutToolbarItem implements ToolbarItemInterface $shortcutNamePrepend = ''; $url = isset($parsedBody['url']) ? $parsedBody['url'] : $queryParams['url']; + // Use given display name + if (!empty($parsedBody['displayName'])) { + $shortcutName = $parsedBody['displayName']; + } + // Determine shortcut type $url = rawurldecode($url); $queryParts = parse_url($url); diff --git a/typo3/sysext/backend/Classes/Template/Components/Buttons/Action/ShortcutButton.php b/typo3/sysext/backend/Classes/Template/Components/Buttons/Action/ShortcutButton.php index c560dcd2a91e..e31d94bbb404 100644 --- a/typo3/sysext/backend/Classes/Template/Components/Buttons/Action/ShortcutButton.php +++ b/typo3/sysext/backend/Classes/Template/Components/Buttons/Action/ShortcutButton.php @@ -14,7 +14,7 @@ namespace TYPO3\CMS\Backend\Template\Components\Buttons\Action; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Backend\Template\DocumentTemplate; +use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface; use TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface; @@ -45,6 +45,11 @@ class ShortcutButton implements ButtonInterface, PositionInterface */ protected $moduleName; + /** + * @var string + */ + protected $displayName; + /** * @var array */ @@ -82,6 +87,28 @@ class ShortcutButton implements ButtonInterface, PositionInterface return $this; } + /** + * Gets the display name of the module. + * + * @return string + */ + public function getDisplayName() + { + return $this->displayName; + } + + /** + * Sets the display name of the module. + * + * @param string $displayName + * @return ShortcutButton + */ + public function setDisplayName($displayName) + { + $this->displayName = $displayName; + return $this; + } + /** * Gets the SET variables. * @@ -190,14 +217,14 @@ class ShortcutButton implements ButtonInterface, PositionInterface public function render() { if ($this->getBackendUser()->mayMakeShortcut()) { - /** @var DocumentTemplate $documentTemplate */ - $documentTemplate = GeneralUtility::makeInstance(DocumentTemplate::class); - $shortcutMarkup = $documentTemplate->makeShortcutIcon( + /** @var ModuleTemplate $moduleTemplate */ + $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); + $shortcutMarkup = $moduleTemplate->makeShortcutIcon( implode(',', $this->getVariables), implode(',', $this->setVariables), $this->moduleName, '', - 'btn btn-sm btn-default' + $this->displayName ); } else { $shortcutMarkup = ''; diff --git a/typo3/sysext/backend/Classes/Template/ModuleTemplate.php b/typo3/sysext/backend/Classes/Template/ModuleTemplate.php index 079257ab756c..a0140a75fa10 100644 --- a/typo3/sysext/backend/Classes/Template/ModuleTemplate.php +++ b/typo3/sysext/backend/Classes/Template/ModuleTemplate.php @@ -492,13 +492,17 @@ class ModuleTemplate * is sent to the shortcut script (so - not a fixed value!) - that is used * in file_edit and wizard_rte modules where those are really running as * a part of another module. + * @param string $displayName When given this name is used instead of the + * module name. + * @param string $classes Additional CSS classes for the link around the icon * * @return string HTML content * @todo Make this thing return a button object * @internal */ - public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '') + public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm') { + $gvList = 'route,' . $gvList; $storeUrl = $this->makeShortcutUrl($gvList, $setList); $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI')); // Fallback for alt_mod. We still pass in the old xMOD... stuff, @@ -525,15 +529,15 @@ class ModuleTemplate $shortcutExist = BackendUtility::shortcutExists($shortcutUrl); if ($shortcutExist) { - return '<a class="active" title="">' . + return '<a class="active ' . htmlspecialchars($classes) . '" title="">' . $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>'; } $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl)); $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) . - ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this);return false;'; + ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this, ' . GeneralUtility::quoteJSvalue($displayName) . ');return false;'; - return '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . + return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark', true) . '">' . $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>'; } diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ShortcutMenu.js b/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ShortcutMenu.js index ca2fb2ae78a4..5a57450e762a 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ShortcutMenu.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ShortcutMenu.js @@ -118,7 +118,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Icons'], functio * @param {String} motherModule * @param {Object} shortcutButton */ - ShortcutMenu.createShortcut = function(moduleName, url, confirmationText, motherModule, shortcutButton) { + ShortcutMenu.createShortcut = function(moduleName, url, confirmationText, motherModule, shortcutButton, displayName) { if (typeof confirmationText !== 'undefined') { // @todo: translations Modal.confirm('Create bookmark', confirmationText) @@ -136,7 +136,8 @@ define(['jquery', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/Icons'], functio data: { module: moduleName, url: url, - motherModName: motherModule + motherModName: motherModule, + displayName: displayName }, cache: false }).done(function() { -- GitLab