[TASK] Removes extra empty lines
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Backend\Template\DocumentTemplate;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
27 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
28 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
29
30 /**
31 * View helper which returns shortcut button with icon
32 * Note: This view helper is experimental!
33 *
34 * = Examples =
35 *
36 * <code title="Default">
37 * <f:be.buttons.shortcut />
38 * </code>
39 * <output>
40 * Shortcut button as known from the TYPO3 backend.
41 * By default the current page id, module name and all module arguments will be stored
42 * </output>
43 *
44 * <code title="Explicitly set parameters to be stored in the shortcut">
45 * <f:be.buttons.shortcut getVars="{0: 'M', 1: 'myOwnPrefix'}" setVars="{0: 'function'}" />
46 * </code>
47 * <output>
48 * Shortcut button as known from the TYPO3 backend.
49 * This time only the specified GET parameters and SET[]-settings will be stored.
50 * Note:
51 * Normally you won't need to set getVars & setVars parameters in Extbase modules
52 * </output>
53 */
54 class ShortcutViewHelper extends AbstractBackendViewHelper implements CompilableInterface
55 {
56 /**
57 * Renders a shortcut button as known from the TYPO3 backend
58 *
59 * @param array $getVars list of GET variables to store. By default the current id, module and all module arguments
60 * will be stored
61 * @param array $setVars list of SET[] variables to store. See
62 * \TYPO3\CMS\Backend\Template\DocumentTemplate::makeShortcutIcon(). Normally won't be used by Extbase modules
63 *
64 * @return string the rendered shortcut button
65 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::makeShortcutIcon()
66 */
67
68 public function render(array $getVars = array(), array $setVars = array())
69 {
70 return static::renderStatic(
71 array(
72 'getVars' => $getVars,
73 'setVars' => $setVars
74 ),
75 $this->buildRenderChildrenClosure(),
76 $this->renderingContext
77 );
78 }
79
80 /**
81 * @param array $arguments
82 * @param callable $renderChildrenClosure
83 * @param RenderingContextInterface $renderingContext
84 * @return string
85 */
86 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
87 {
88 $getVars = $arguments['getVars'];
89 $setVars = $arguments['setVars'];
90
91 $mayMakeShortcut = $GLOBALS['BE_USER']->mayMakeShortcut();
92
93 if ($mayMakeShortcut) {
94 $doc = GeneralUtility::makeInstance(DocumentTemplate::class);
95 $currentRequest = $renderingContext->getControllerContext()->getRequest();
96 $extensionName = $currentRequest->getControllerExtensionName();
97 $moduleName = $currentRequest->getPluginName();
98 if (count($getVars) === 0) {
99 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
100 $getVars = array('id', 'M', $modulePrefix);
101 }
102 $getList = implode(',', $getVars);
103 $setList = implode(',', $setVars);
104 return $doc->makeShortcutIcon($getList, $setList, $moduleName);
105 }
106 return '';
107 }
108 }