‪TYPO3CMS  10.4
ShortcutButton.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 
40 {
44  protected ‪$moduleName;
45 
49  protected ‪$displayName;
50 
54  protected ‪$setVariables = [];
55 
59  protected ‪$getVariables = [];
60 
64  protected ‪$controllerContext;
65 
71  public function ‪getModuleName()
72  {
73  return ‪$this->moduleName;
74  }
75 
82  public function ‪setModuleName(‪$moduleName)
83  {
84  $this->moduleName = ‪$moduleName;
85  return $this;
86  }
87 
93  public function ‪getDisplayName()
94  {
95  return ‪$this->displayName;
96  }
97 
104  public function ‪setDisplayName(‪$displayName)
105  {
106  $this->displayName = ‪$displayName;
107  return $this;
108  }
109 
115  public function ‪getSetVariables()
116  {
117  return ‪$this->setVariables;
118  }
119 
126  public function ‪setSetVariables(array ‪$setVariables)
127  {
128  $this->setVariables = ‪$setVariables;
129  return $this;
130  }
131 
137  public function ‪getGetVariables()
138  {
139  return ‪$this->getVariables;
140  }
141 
148  public function ‪setGetVariables(array ‪$getVariables)
149  {
150  $this->getVariables = ‪$getVariables;
151  return $this;
152  }
153 
159  public function ‪getPosition()
160  {
162  }
163 
169  public function ‪getGroup()
170  {
171  return 91;
172  }
173 
179  public function ‪getType()
180  {
181  return static::class;
182  }
183 
191  public function ‪isValid()
192  {
193  $this->‪preProcess();
194 
195  return
196  !empty($this->moduleName)
197  ;
198  }
199 
205  public function ‪__toString()
206  {
207  return $this->‪render();
208  }
209 
215  public function ‪render()
216  {
217  if ($this->‪getBackendUser()->mayMakeShortcut()) {
219  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
220  $shortcutMarkup = $moduleTemplate->makeShortcutIcon(
221  implode(',', $this->getVariables),
222  implode(',', $this->setVariables),
223  $this->moduleName,
224  '',
225  $this->displayName
226  );
227  } else {
228  $shortcutMarkup = '';
229  }
230 
231  return $shortcutMarkup;
232  }
233 
237  protected function ‪preProcess()
238  {
239  $emptyGetVariables = (count($this->getVariables) === 0);
240 
241  // Set default GET parameters
242  if ($emptyGetVariables) {
243  $this->getVariables = ['id', 'route'];
244  }
245 
246  // Automatically determine module name in Extbase context
247  if ($this->controllerContext !== null) {
248  $currentRequest = $this->controllerContext->getRequest();
249  $extensionName = $currentRequest->getControllerExtensionName();
250  $this->moduleName = $currentRequest->getPluginName();
251  // Extend default GET parameters
252  if ($emptyGetVariables) {
253  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $this->moduleName);
254  $this->getVariables[] = $modulePrefix;
255  }
256  }
257  }
258 
262  protected function ‪getBackendUser()
263  {
264  return ‪$GLOBALS['BE_USER'];
265  }
266 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action
Definition: HelpButton.php:16
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setGetVariables
‪ShortcutButton setGetVariables(array $getVariables)
Definition: ShortcutButton.php:143
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\__toString
‪string __toString()
Definition: ShortcutButton.php:200
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setModuleName
‪ShortcutButton setModuleName($moduleName)
Definition: ShortcutButton.php:77
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getModuleName
‪string getModuleName()
Definition: ShortcutButton.php:66
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$displayName
‪string $displayName
Definition: ShortcutButton.php:47
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getGetVariables
‪array getGetVariables()
Definition: ShortcutButton.php:132
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ShortcutButton.php:257
‪TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface
Definition: PositionInterface.php:22
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getGroup
‪int getGroup()
Definition: ShortcutButton.php:164
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setDisplayName
‪ShortcutButton setDisplayName($displayName)
Definition: ShortcutButton.php:99
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton
Definition: ShortcutButton.php:40
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getDisplayName
‪string getDisplayName()
Definition: ShortcutButton.php:88
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\isValid
‪bool isValid()
Definition: ShortcutButton.php:186
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getSetVariables
‪array getSetVariables()
Definition: ShortcutButton.php:110
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getPosition
‪string getPosition()
Definition: ShortcutButton.php:154
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\getType
‪string getType()
Definition: ShortcutButton.php:174
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\setSetVariables
‪ShortcutButton setSetVariables(array $setVariables)
Definition: ShortcutButton.php:121
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$moduleName
‪string $moduleName
Definition: ShortcutButton.php:43
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$getVariables
‪array $getVariables
Definition: ShortcutButton.php:55
‪$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:51
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\$controllerContext
‪ControllerContext $controllerContext
Definition: ShortcutButton.php:59
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\render
‪string render()
Definition: ShortcutButton.php:210
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton\preProcess
‪preProcess()
Definition: ShortcutButton.php:232
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22