[BUGFIX] Streamline iframe namings for new backend
[Packages/TYPO3.CMS.git] / typo3 / sysext / sys_action / Classes / Backend / ToolbarItems / ActionToolbarItem.php
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
17 use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
21 use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\SysAction\ActionTask;
26
27 /**
28 * Adds action links to the backend's toolbar
29 */
30 class ActionToolbarItem implements ToolbarItemInterface
31 {
32 /**
33 * @var array List of action entries
34 */
35 protected $actionEntries = [];
36
37 /**
38 * @var IconFactory
39 */
40 protected $iconFactory;
41
42 /**
43 * Constructor
44 */
45 public function __construct()
46 {
47 $this->getLanguageService()->includeLLFile('EXT:sys_action/Resources/Private/Language/locallang.xlf');
48 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
49 $this->initializeActionEntries();
50 }
51
52 /**
53 * Render toolbar icon
54 *
55 * @return string HTML
56 */
57 public function getItem()
58 {
59 $title = htmlspecialchars($this->getLanguageService()->getLL('action_toolbaritem'));
60 $icon = $this->iconFactory->getIcon('apps-toolbar-menu-actions', Icon::SIZE_SMALL)->render('inline');
61 return '
62 <span class="toolbar-item-icon" title="' . $title . '">' . $icon . '</span>
63 <span class="toolbar-item-title">' . $title . '</span>
64 ';
65 }
66
67 /**
68 * Render drop down
69 *
70 * @return string HTML
71 */
72 public function getDropDown()
73 {
74 $actionMenu = [];
75 $actionMenu[] = '<h3 class="dropdown-headline">' . htmlspecialchars($this->getLanguageService()->getLL('sys_action')) . '</h3>';
76 $actionMenu[] = '<hr>';
77 $actionMenu[] = '<div class="dropdown-table">';
78 foreach ($this->actionEntries as $linkConf) {
79 $actionMenu[] = '<div class="dropdown-table-row">';
80 $actionMenu[] = '<div class="dropdown-table-column dropdown-table-icon">';
81 $actionMenu[] = $linkConf[2];
82 $actionMenu[] = '</div>';
83 $actionMenu[] = '<div class="dropdown-table-column dropdown-table-title">';
84 $actionMenu[] = '<a class="t3js-topbar-link" href="' . htmlspecialchars($linkConf[1]) . '" target="list_frame">';
85 $actionMenu[] = htmlspecialchars($linkConf[0]);
86 $actionMenu[] = '</a>';
87 $actionMenu[] = '</div>';
88 $actionMenu[] = '</div>';
89 }
90 $actionMenu[] = '</div>';
91 return implode(LF, $actionMenu);
92 }
93
94 /**
95 * Gets the entries for the action menu
96 */
97 protected function initializeActionEntries()
98 {
99 $backendUser = $this->getBackendUser();
100
101 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_action');
102 $queryBuilder->getRestrictions()
103 ->removeAll()
104 ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
105 ->add(GeneralUtility::makeInstance(RootLevelRestriction::class, [
106 'sys_action'
107 ]));
108
109 $queryBuilder
110 ->select('sys_action.*')
111 ->from('sys_action');
112
113 if (!empty($GLOBALS['TCA']['sys_action']['ctrl']['sortby'])) {
114 $queryBuilder->orderBy('sys_action.' . $GLOBALS['TCA']['sys_action']['ctrl']['sortby']);
115 }
116
117 $actions = [];
118 if (!$backendUser->isAdmin()) {
119 $groupList = $backendUser->groupList ?: '0';
120
121 $queryBuilder
122 ->join(
123 'sys_action',
124 'sys_action_asgr_mm',
125 'sys_action_asgr_mm',
126 $queryBuilder->expr()->eq(
127 'sys_action_asgr_mm.uid_local',
128 $queryBuilder->quoteIdentifier('sys_action.uid')
129 )
130 )
131 ->join(
132 'sys_action_asgr_mm',
133 'be_groups',
134 'be_groups',
135 $queryBuilder->expr()->eq(
136 'sys_action_asgr_mm.uid_foreign',
137 $queryBuilder->quoteIdentifier('be_groups.uid')
138 )
139 )
140 ->where($queryBuilder->expr()->in('be_groups.uid', GeneralUtility::intExplode(',', $groupList, true)))
141 ->groupBy('sys_action.uid');
142 }
143
144 $result = $queryBuilder->execute();
145 while ($actionRow = $result->fetch()) {
146 $actions[] = [
147 $actionRow['title'],
148 sprintf(
149 '%s&SET[mode]=tasks&SET[function]=sys_action.%s&show=%u',
150 BackendUtility::getModuleUrl('user_task'),
151 ActionTask::class, // @todo: class name string is hand over as url parameter?!
152 $actionRow['uid']
153 ),
154 $this->iconFactory->getIconForRecord('sys_action', $actionRow, Icon::SIZE_SMALL)->render()
155 ];
156 }
157 $this->actionEntries = $actions;
158 }
159
160 /**
161 * This toolbar needs no additional attributes
162 *
163 * @return array
164 */
165 public function getAdditionalAttributes()
166 {
167 return [];
168 }
169
170 /**
171 * This item has a drop down
172 *
173 * @return bool
174 */
175 public function hasDropDown()
176 {
177 return true;
178 }
179
180 /**
181 * This toolbar is rendered if there are action entries, no further user restriction
182 *
183 * @return bool TRUE
184 */
185 public function checkAccess()
186 {
187 $result = false;
188 if (!empty($this->actionEntries)) {
189 $result = true;
190 }
191 return $result;
192 }
193
194 /**
195 * Position relative to others
196 *
197 * @return int
198 */
199 public function getIndex()
200 {
201 return 35;
202 }
203
204 /**
205 * Returns the current BE user.
206 *
207 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
208 */
209 protected function getBackendUser()
210 {
211 return $GLOBALS['BE_USER'];
212 }
213
214 /**
215 * Returns LanguageService
216 *
217 * @return \TYPO3\CMS\Lang\LanguageService
218 */
219 protected function getLanguageService()
220 {
221 return $GLOBALS['LANG'];
222 }
223 }