TYPO3 CMS  TYPO3_8-7
ActionToolbarItem.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 
26 
31 {
35  protected $availableActions = [];
36 
42  public function getItem()
43  {
44  return $this->getFluidTemplateObject('ToolbarItem.html')->render();
45  }
46 
52  public function getDropDown()
53  {
54  $view = $this->getFluidTemplateObject('DropDown.html');
55  $view->assign('actions', $this->availableActions);
56  return $view->render();
57  }
58 
62  protected function setAvailableActions()
63  {
64  $actionEntries = [];
65  $backendUser = $this->getBackendUser();
66 
67  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_action');
68  $queryBuilder->getRestrictions()
69  ->removeAll()
70  ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
71  ->add(GeneralUtility::makeInstance(RootLevelRestriction::class, [
72  'sys_action'
73  ]));
74 
75  $queryBuilder
76  ->select('sys_action.*')
77  ->from('sys_action');
78 
79  if (!empty($GLOBALS['TCA']['sys_action']['ctrl']['sortby'])) {
80  $queryBuilder->orderBy('sys_action.' . $GLOBALS['TCA']['sys_action']['ctrl']['sortby']);
81  }
82 
83  if (!$backendUser->isAdmin()) {
84  $groupList = $backendUser->groupList ?: '0';
85 
86  $queryBuilder
87  ->join(
88  'sys_action',
89  'sys_action_asgr_mm',
90  'sys_action_asgr_mm',
91  $queryBuilder->expr()->eq(
92  'sys_action_asgr_mm.uid_local',
93  $queryBuilder->quoteIdentifier('sys_action.uid')
94  )
95  )
96  ->join(
97  'sys_action_asgr_mm',
98  'be_groups',
99  'be_groups',
100  $queryBuilder->expr()->eq(
101  'sys_action_asgr_mm.uid_foreign',
102  $queryBuilder->quoteIdentifier('be_groups.uid')
103  )
104  )
105  ->where(
106  $queryBuilder->expr()->in(
107  'be_groups.uid',
108  $queryBuilder->createNamedParameter(
109  GeneralUtility::intExplode(',', $groupList, true),
110  Connection::PARAM_INT_ARRAY
111  )
112  )
113  )
114  ->groupBy('sys_action.uid');
115  }
116 
117  $result = $queryBuilder->execute();
118  while ($actionRow = $result->fetch()) {
119  $actionRow['link'] = sprintf(
120  '%s&SET[mode]=tasks&SET[function]=sys_action.%s&show=%u',
121  BackendUtility::getModuleUrl('user_task'),
122  ActionTask::class, // @todo: class name string is hand over as url parameter?!
123  $actionRow['uid']
124  );
125  $actionEntries[] = $actionRow;
126  }
127 
128  $this->availableActions = $actionEntries;
129  }
130 
136  public function getAdditionalAttributes()
137  {
138  return [];
139  }
140 
146  public function hasDropDown()
147  {
148  return true;
149  }
150 
156  public function checkAccess()
157  {
158  $this->setAvailableActions();
159  return !empty($this->availableActions);
160  }
161 
167  public function getIndex()
168  {
169  return 35;
170  }
171 
177  protected function getBackendUser()
178  {
179  return $GLOBALS['BE_USER'];
180  }
181 
188  protected function getFluidTemplateObject(string $filename): StandaloneView
189  {
190  $view = GeneralUtility::makeInstance(StandaloneView::class);
191  $view->setLayoutRootPaths(['EXT:sys_action/Resources/Private/Layouts']);
192  $view->setPartialRootPaths([
193  'EXT:backend/Resources/Private/Partials/ToolbarItems',
194  'EXT:sys_action/Resources/Private/Partials'
195  ]);
196  $view->setTemplateRootPaths(['EXT:sys_action/Resources/Private/Templates/ToolbarItems']);
197  $view->setTemplate($filename);
198 
199  $view->getRequest()->setControllerExtensionName('SysAction');
200  return $view;
201  }
202 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']