‪TYPO3CMS  9.5
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 
25 
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 
118  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
119  $result = $queryBuilder->execute();
120  while ($actionRow = $result->fetch()) {
121  $actionRow['link'] = sprintf(
122  '%s&SET[mode]=tasks&SET[function]=sys_action.%s&show=%u',
123  (string)$uriBuilder->buildUriFromRoute('user_task'),
124  ActionTask::class, // @todo: class name string is hand over as url parameter?!
125  $actionRow['uid']
126  );
127  $actionEntries[] = $actionRow;
128  }
129 
130  $this->availableActions = $actionEntries;
131  }
132 
138  public function ‪getAdditionalAttributes()
139  {
140  return [];
141  }
142 
148  public function ‪hasDropDown()
149  {
150  return true;
151  }
152 
158  public function ‪checkAccess()
159  {
160  $this->‪setAvailableActions();
161  return !empty($this->availableActions);
162  }
163 
169  public function ‪getIndex()
170  {
171  return 35;
172  }
173 
179  protected function ‪getBackendUser()
180  {
181  return ‪$GLOBALS['BE_USER'];
182  }
183 
190  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
191  {
192  $view = GeneralUtility::makeInstance(StandaloneView::class);
193  $view->setLayoutRootPaths(['EXT:sys_action/Resources/Private/Layouts']);
194  $view->setPartialRootPaths([
195  'EXT:backend/Resources/Private/Partials/ToolbarItems',
196  'EXT:sys_action/Resources/Private/Partials'
197  ]);
198  $view->setTemplateRootPaths(['EXT:sys_action/Resources/Private/Templates/ToolbarItems']);
199  $view->setTemplate($filename);
200 
201  $view->getRequest()->setControllerExtensionName('SysAction');
202  return $view;
203  }
204 }
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: ActionToolbarItem.php:189
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:25
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:24
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem
Definition: ActionToolbarItem.php:31
‪TYPO3
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\setAvailableActions
‪setAvailableActions()
Definition: ActionToolbarItem.php:61
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: ActionToolbarItem.php:137
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: ActionToolbarItem.php:147
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\$availableActions
‪array $availableActions
Definition: ActionToolbarItem.php:34
‪TYPO3\CMS\SysAction\ActionTask
Definition: ActionTask.php:38
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\checkAccess
‪bool checkAccess()
Definition: ActionToolbarItem.php:157
‪TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction
Definition: RootLevelRestriction.php:25
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getDropDown
‪string getDropDown()
Definition: ActionToolbarItem.php:51
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: ActionToolbarItem.php:178
‪TYPO3\CMS\SysAction\Backend\ToolbarItems
Definition: ActionToolbarItem.php:2
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getItem
‪string getItem()
Definition: ActionToolbarItem.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\SysAction\Backend\ToolbarItems\ActionToolbarItem\getIndex
‪int getIndex()
Definition: ActionToolbarItem.php:168