‪TYPO3CMS  11.5
ShortcutButtonViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
25 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
26 
46 {
52  public function ‪initializeArguments(): void
53  {
54  parent::initializeArguments();
55  $this->registerArgument('displayName', 'string', 'Name for the shortcut', false, '');
56  $this->registerArgument('arguments', 'array', 'List of relevant GET variables as key/values list to store', false, []);
57  $this->registerArgument('getVars', 'array', 'List of additional GET variables to store. The current id, module and all module arguments will always be stored', false, []);
58  }
59 
60  protected static function ‪createButton(‪ButtonBar $buttonBar, array $arguments, RenderingContextInterface $renderingContext): ‪ButtonInterface
61  {
62  $currentRequest = $renderingContext->getRequest();
63  $moduleName = $currentRequest->getPluginName();
64  $displayName = $arguments['displayName'];
65 
66  // Initialize the shortcut button
67  $shortcutButton = $buttonBar
69  ->‪setDisplayName($displayName)
70  ->‪setRouteIdentifier(self::getRouteIdentifierForModuleName($moduleName));
71 
72  if (!empty($arguments['arguments'])) {
73  $shortcutButton->‪setArguments($arguments['arguments']);
74  } else {
75  $extensionName = $currentRequest->getControllerExtensionName();
76  $argumentPrefix = GeneralUtility::makeInstance(ExtensionService::class)
77  ->getPluginNamespace($extensionName, $moduleName);
78  $getVars = $arguments['getVars'];
79  $getVars[] = $argumentPrefix;
80  $shortcutButton->setGetVariables($getVars);
81  }
82 
83  return $shortcutButton;
84  }
85 
92  protected static function ‪getRouteIdentifierForModuleName(string $moduleName): string
93  {
94  foreach (GeneralUtility::makeInstance(Router::class)->getRoutes() as $identifier => $route) {
95  if ($route->hasOption('moduleName') && $route->getOption('moduleName') === $moduleName) {
96  return $identifier;
97  }
98  }
99 
100  return '';
101  }
102 }
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button\AbstractButtonViewHelper
Definition: AbstractButtonViewHelper.php:38
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button\ShortcutButtonViewHelper\initializeArguments
‪initializeArguments()
Definition: ShortcutButtonViewHelper.php:52
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setArguments
‪$this setArguments(array $arguments)
Definition: ShortcutButton.php:160
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setRouteIdentifier
‪ShortcutButton setRouteIdentifier(string $routeIdentifier)
Definition: ShortcutButton.php:102
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button\ShortcutButtonViewHelper
Definition: ShortcutButtonViewHelper.php:46
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button\ShortcutButtonViewHelper\getRouteIdentifierForModuleName
‪static string getRouteIdentifierForModuleName(string $moduleName)
Definition: ShortcutButtonViewHelper.php:92
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setDisplayName
‪ShortcutButton setDisplayName($displayName)
Definition: ShortcutButton.php:150
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button
Definition: AbstractButtonViewHelper.php:18
‪TYPO3\CMS\Extbase\Service\ExtensionService
Definition: ExtensionService.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayout\Button\ShortcutButtonViewHelper\createButton
‪static createButton(ButtonBar $buttonBar, array $arguments, RenderingContextInterface $renderingContext)
Definition: ShortcutButtonViewHelper.php:60
‪TYPO3\CMS\Backend\Routing\Router
Definition: Router.php:39
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeShortcutButton
‪ShortcutButton makeShortcutButton()
Definition: ButtonBar.php:141
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22