[TASK] Remove nearly any evidence of jQuery in dashboard
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Buttons / ShortcutViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Buttons;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Template\ModuleTemplate;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21
22 /**
23 * ViewHelper which returns shortcut button with icon.
24 *
25 * .. note::
26 * This ViewHelper is experimental!
27 *
28 * Examples
29 * ========
30 *
31 * Default::
32 *
33 * <f:be.buttons.shortcut />
34 *
35 * Shortcut button as known from the TYPO3 backend.
36 * By default the current page id, module name and all module arguments will be stored.
37 *
38 * Explicitly set parameters to be stored in the shortcut::
39 *
40 * <f:be.buttons.shortcut getVars="{0: 'route', 1: 'myOwnPrefix'}" setVars="{0: 'function'}" />
41 *
42 * Shortcut button as known from the TYPO3 backend.
43 * This time only the specified GET parameters and SET[]-settings will be stored.
44 *
45 * .. note:
46 *
47 * Normally you won't need to set getVars & setVars parameters in Extbase modules.
48 */
49 class ShortcutViewHelper extends AbstractBackendViewHelper
50 {
51 /**
52 * As this ViewHelper renders HTML, the output must not be escaped.
53 *
54 * @var bool
55 */
56 protected $escapeOutput = false;
57
58 /**
59 * Initialize arguments.
60 *
61 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
62 */
63 public function initializeArguments()
64 {
65 parent::initializeArguments();
66 $this->registerArgument('getVars', 'array', 'List of GET variables to store. By default the current id, module and all module arguments will be stored', false, []);
67 $this->registerArgument('setVars', 'array', 'List of SET[] variables to store. See ModuleTemplate::makeShortcutIcon(). Normally won\'t be used by Extbase modules', false, []);
68 }
69
70 /**
71 * Renders a shortcut button as known from the TYPO3 backend
72 *
73 * @return string the rendered shortcut button
74 * @see ModuleTemplate::makeShortcutIcon()
75 */
76 public function render()
77 {
78 return static::renderStatic(
79 $this->arguments,
80 $this->buildRenderChildrenClosure(),
81 $this->renderingContext
82 );
83 }
84
85 /**
86 * @param array $arguments
87 * @param \Closure $renderChildrenClosure
88 * @param RenderingContextInterface $renderingContext
89 * @return string
90 */
91 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
92 {
93 $getVars = $arguments['getVars'];
94 $setVars = $arguments['setVars'];
95
96 $mayMakeShortcut = $GLOBALS['BE_USER']->mayMakeShortcut();
97
98 if ($mayMakeShortcut) {
99 $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
100 $currentRequest = $renderingContext->getControllerContext()->getRequest();
101 $extensionName = $currentRequest->getControllerExtensionName();
102 $moduleName = $currentRequest->getPluginName();
103 if (count($getVars) === 0) {
104 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
105 $getVars = ['id', 'route', $modulePrefix];
106 }
107 $getList = implode(',', $getVars);
108 $setList = implode(',', $setVars);
109 return $moduleTemplate->makeShortcutIcon($getList, $setList, $moduleName);
110 }
111 return '';
112 }
113 }