‪TYPO3CMS  9.5
ShortcutButton.php
Go to the documentation of this file.
1 <?php
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 
24 
39 {
43  protected ‪$moduleName;
44 
48  protected ‪$displayName;
49 
53  protected ‪$setVariables = [];
54 
58  protected ‪$getVariables = [];
59 
63  protected ‪$controllerContext;
64 
70  public function ‪getModuleName()
71  {
72  return ‪$this->moduleName;
73  }
74 
81  public function ‪setModuleName(‪$moduleName)
82  {
83  $this->moduleName = ‪$moduleName;
84  return $this;
85  }
86 
92  public function ‪getDisplayName()
93  {
94  return ‪$this->displayName;
95  }
96 
103  public function ‪setDisplayName(‪$displayName)
104  {
105  $this->displayName = ‪$displayName;
106  return $this;
107  }
108 
114  public function ‪getSetVariables()
115  {
116  return ‪$this->setVariables;
117  }
118 
125  public function ‪setSetVariables(array ‪$setVariables)
126  {
127  $this->setVariables = ‪$setVariables;
128  return $this;
129  }
130 
136  public function ‪getGetVariables()
137  {
138  return ‪$this->getVariables;
139  }
140 
147  public function ‪setGetVariables(array ‪$getVariables)
148  {
149  $this->getVariables = ‪$getVariables;
150  return $this;
151  }
152 
158  public function ‪getPosition()
159  {
161  }
162 
168  public function ‪getGroup()
169  {
170  return 91;
171  }
172 
178  public function ‪getType()
179  {
180  return static::class;
181  }
182 
190  public function ‪isValid()
191  {
192  $this->‪preProcess();
193 
194  return
195  !empty($this->moduleName)
196  ;
197  }
198 
204  public function ‪__toString()
205  {
206  return $this->‪render();
207  }
208 
214  public function ‪render()
215  {
216  if ($this->‪getBackendUser()->mayMakeShortcut()) {
218  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
219  $shortcutMarkup = $moduleTemplate->makeShortcutIcon(
220  implode(',', $this->getVariables),
221  implode(',', $this->setVariables),
222  $this->moduleName,
223  '',
224  $this->displayName
225  );
226  } else {
227  $shortcutMarkup = '';
228  }
229 
230  return $shortcutMarkup;
231  }
232 
236  protected function ‪preProcess()
237  {
238  $emptyGetVariables = (count($this->getVariables) === 0);
239 
240  // Set default GET parameters
241  if ($emptyGetVariables) {
242  $this->getVariables = ['id', 'route'];
243  }
244 
245  // Automatically determine module name in Extbase context
246  if ($this->controllerContext !== null) {
247  $currentRequest = $this->controllerContext->getRequest();
248  $extensionName = $currentRequest->getControllerExtensionName();
249  $this->moduleName = $currentRequest->getPluginName();
250  // Extend default GET parameters
251  if ($emptyGetVariables) {
252  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $this->moduleName);
253  $this->getVariables[] = $modulePrefix;
254  }
255  }
256  }
257 
261  protected function ‪getBackendUser()
262  {
263  return ‪$GLOBALS['BE_USER'];
264  }
265 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action
Definition: HelpButton.php:2
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setGetVariables
‪ShortcutButton setGetVariables(array $getVariables)
Definition: ShortcutButton.php:142
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\__toString
‪string __toString()
Definition: ShortcutButton.php:199
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setModuleName
‪ShortcutButton setModuleName($moduleName)
Definition: ShortcutButton.php:76
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:21
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getModuleName
‪string getModuleName()
Definition: ShortcutButton.php:65
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$displayName
‪string $displayName
Definition: ShortcutButton.php:46
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getGetVariables
‪array getGetVariables()
Definition: ShortcutButton.php:131
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ShortcutButton.php:256
‪TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface
Definition: PositionInterface.php:21
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getGroup
‪int getGroup()
Definition: ShortcutButton.php:163
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setDisplayName
‪ShortcutButton setDisplayName($displayName)
Definition: ShortcutButton.php:98
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton
Definition: ShortcutButton.php:39
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getDisplayName
‪string getDisplayName()
Definition: ShortcutButton.php:87
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\isValid
‪bool isValid()
Definition: ShortcutButton.php:185
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getSetVariables
‪array getSetVariables()
Definition: ShortcutButton.php:109
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getPosition
‪string getPosition()
Definition: ShortcutButton.php:153
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getType
‪string getType()
Definition: ShortcutButton.php:173
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setSetVariables
‪ShortcutButton setSetVariables(array $setVariables)
Definition: ShortcutButton.php:120
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$moduleName
‪string $moduleName
Definition: ShortcutButton.php:42
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$getVariables
‪array $getVariables
Definition: ShortcutButton.php:54
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$setVariables
‪array $setVariables
Definition: ShortcutButton.php:50
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$controllerContext
‪ControllerContext $controllerContext
Definition: ShortcutButton.php:58
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\render
‪string render()
Definition: ShortcutButton.php:209
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\preProcess
‪preProcess()
Definition: ShortcutButton.php:231
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:40
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:21