TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ActionToolbarItem.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\SysAction\Backend\ToolbarItems;
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 
27 
32 {
36  protected $actionEntries = [];
37 
41  protected $iconFactory;
42 
46  public function __construct()
47  {
48  $this->getLanguageService()->includeLLFile('EXT:sys_action/Resources/Private/Language/locallang.xlf');
49  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
50  $this->initializeActionEntries();
51  }
52 
58  public function getItem()
59  {
60  $title = htmlspecialchars($this->getLanguageService()->getLL('action_toolbaritem'));
61  $icon = $this->iconFactory->getIcon('apps-toolbar-menu-actions', Icon::SIZE_SMALL)->render('inline');
62  return '
63  <span class="toolbar-item-icon" title="' . $title . '">' . $icon . '</span>
64  <span class="toolbar-item-title">' . $title . '</span>
65  ';
66  }
67 
73  public function getDropDown()
74  {
75  $actionMenu = [];
76  $actionMenu[] = '<h3 class="dropdown-headline">' . htmlspecialchars($this->getLanguageService()->getLL('sys_action')) . '</h3>';
77  $actionMenu[] = '<hr>';
78  $actionMenu[] = '<div class="dropdown-table">';
79  foreach ($this->actionEntries as $linkConf) {
80  $actionMenu[] = '<div class="dropdown-table-row">';
81  $actionMenu[] = '<div class="dropdown-table-column dropdown-table-icon">';
82  $actionMenu[] = $linkConf[2];
83  $actionMenu[] = '</div>';
84  $actionMenu[] = '<div class="dropdown-table-column dropdown-table-title">';
85  $actionMenu[] = '<a class="t3js-topbar-link" href="' . htmlspecialchars($linkConf[1]) . '" target="list_frame">';
86  $actionMenu[] = htmlspecialchars($linkConf[0]);
87  $actionMenu[] = '</a>';
88  $actionMenu[] = '</div>';
89  $actionMenu[] = '</div>';
90  }
91  $actionMenu[] = '</div>';
92  return implode(LF, $actionMenu);
93  }
94 
98  protected function initializeActionEntries()
99  {
100  $backendUser = $this->getBackendUser();
101 
102  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_action');
103  $queryBuilder->getRestrictions()
104  ->removeAll()
105  ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
106  ->add(GeneralUtility::makeInstance(RootLevelRestriction::class, [
107  'sys_action'
108  ]));
109 
110  $queryBuilder
111  ->select('sys_action.*')
112  ->from('sys_action');
113 
114  if (!empty($GLOBALS['TCA']['sys_action']['ctrl']['sortby'])) {
115  $queryBuilder->orderBy('sys_action.' . $GLOBALS['TCA']['sys_action']['ctrl']['sortby']);
116  }
117 
118  $actions = [];
119  if (!$backendUser->isAdmin()) {
120  $groupList = $backendUser->groupList ?: '0';
121 
122  $queryBuilder
123  ->join(
124  'sys_action',
125  'sys_action_asgr_mm',
126  'sys_action_asgr_mm',
127  $queryBuilder->expr()->eq(
128  'sys_action_asgr_mm.uid_local',
129  $queryBuilder->quoteIdentifier('sys_action.uid')
130  )
131  )
132  ->join(
133  'sys_action_asgr_mm',
134  'be_groups',
135  'be_groups',
136  $queryBuilder->expr()->eq(
137  'sys_action_asgr_mm.uid_foreign',
138  $queryBuilder->quoteIdentifier('be_groups.uid')
139  )
140  )
141  ->where(
142  $queryBuilder->expr()->in(
143  'be_groups.uid',
144  $queryBuilder->createNamedParameter(
145  GeneralUtility::intExplode(',', $groupList, true),
146  Connection::PARAM_INT_ARRAY
147  )
148  )
149  )
150  ->groupBy('sys_action.uid');
151  }
152 
153  $result = $queryBuilder->execute();
154  while ($actionRow = $result->fetch()) {
155  $actions[] = [
156  $actionRow['title'],
157  sprintf(
158  '%s&SET[mode]=tasks&SET[function]=sys_action.%s&show=%u',
159  BackendUtility::getModuleUrl('user_task'),
160  ActionTask::class, // @todo: class name string is hand over as url parameter?!
161  $actionRow['uid']
162  ),
163  $this->iconFactory->getIconForRecord('sys_action', $actionRow, Icon::SIZE_SMALL)->render()
164  ];
165  }
166  $this->actionEntries = $actions;
167  }
168 
174  public function getAdditionalAttributes()
175  {
176  return [];
177  }
178 
184  public function hasDropDown()
185  {
186  return true;
187  }
188 
194  public function checkAccess()
195  {
196  $result = false;
197  if (!empty($this->actionEntries)) {
198  $result = true;
199  }
200  return $result;
201  }
202 
208  public function getIndex()
209  {
210  return 35;
211  }
212 
218  protected function getBackendUser()
219  {
220  return $GLOBALS['BE_USER'];
221  }
222 
228  protected function getLanguageService()
229  {
230  return $GLOBALS['LANG'];
231  }
232 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)