TYPO3  7.6
ShortcutButton.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components\Buttons\Action;
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 
42 {
46  protected $moduleName;
47 
51  protected $displayName;
52 
56  protected $setVariables = array();
57 
61  protected $getVariables = array();
62 
66  protected $controllerContext;
67 
73  public function getModuleName()
74  {
75  return $this->moduleName;
76  }
77 
84  public function setModuleName($moduleName)
85  {
86  $this->moduleName = $moduleName;
87  return $this;
88  }
89 
95  public function getDisplayName()
96  {
97  return $this->displayName;
98  }
99 
106  public function setDisplayName($displayName)
107  {
108  $this->displayName = $displayName;
109  return $this;
110  }
111 
117  public function getSetVariables()
118  {
119  return $this->setVariables;
120  }
121 
128  public function setSetVariables(array $setVariables)
129  {
130  $this->setVariables = $setVariables;
131  return $this;
132  }
133 
139  public function getGetVariables()
140  {
141  return $this->getVariables;
142  }
143 
150  public function setGetVariables(array $getVariables)
151  {
152  $this->getVariables = $getVariables;
153  return $this;
154  }
155 
161  public function getPosition()
162  {
164  }
165 
171  public function getGroup()
172  {
173  return 91;
174  }
175 
181  public function getType()
182  {
183  return get_class($this);
184  }
185 
193  public function isValid()
194  {
195  $this->preProcess();
196 
197  return (
198  !empty($this->moduleName)
199  );
200  }
201 
207  public function __toString()
208  {
209  return $this->render();
210  }
211 
217  public function render()
218  {
219  if ($this->getBackendUser()->mayMakeShortcut()) {
221  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
222  $shortcutMarkup = $moduleTemplate->makeShortcutIcon(
223  implode(',', $this->getVariables),
224  implode(',', $this->setVariables),
225  $this->moduleName,
226  '',
227  $this->displayName
228  );
229  } else {
230  $shortcutMarkup = '';
231  }
232 
233  return $shortcutMarkup;
234  }
235 
239  protected function preProcess()
240  {
241  $emptyGetVariables = (count($this->getVariables) === 0);
242 
243  // Set default GET parameters
244  if ($emptyGetVariables) {
245  $this->getVariables = array('id', 'M');
246  }
247 
248  // Automatically determine module name in Extbase context
249  if ($this->controllerContext !== null) {
250  $currentRequest = $this->controllerContext->getRequest();
251  $extensionName = $currentRequest->getControllerExtensionName();
252  $this->moduleName = $currentRequest->getPluginName();
253  // Extend default GET parameters
254  if ($emptyGetVariables) {
255  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $this->moduleName);
256  $this->getVariables[] = $modulePrefix;
257  }
258  }
259  }
260 
264  protected function getBackendUser()
265  {
266  return $GLOBALS['BE_USER'];
267  }
268 }