f0e20937097cc6d02fae2fe19c6af0b8cf89cae7
[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\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Adds action links to the backend's toolbar
25 */
26 class ActionToolbarItem implements ToolbarItemInterface
27 {
28 /**
29 * @var array List of action entries
30 */
31 protected $actionEntries = array();
32
33 /**
34 * @var IconFactory
35 */
36 protected $iconFactory;
37
38 /**
39 * Constructor
40 */
41 public function __construct()
42 {
43 $this->getLanguageService()->includeLLFile('EXT:sys_action/Resources/Private/Language/locallang.xlf');
44 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
45 $this->initializeActionEntries();
46 }
47
48 /**
49 * Render toolbar icon
50 *
51 * @return string HTML
52 */
53 public function getItem()
54 {
55 $title = htmlspecialchars($this->getLanguageService()->getLL('action_toolbaritem'));
56 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('apps-toolbar-menu-actions', Icon::SIZE_SMALL)->render('inline') . '</span>';
57 }
58
59 /**
60 * Render drop down
61 *
62 * @return string HTML
63 */
64 public function getDropDown()
65 {
66 $actionMenu = array();
67 $actionMenu[] = '<ul class="dropdown-list">';
68 foreach ($this->actionEntries as $linkConf) {
69 $actionMenu[] = '<li>';
70 $actionMenu[] = '<a href="' . htmlspecialchars($linkConf[1]) . '" target="content" class="dropdown-list-link">';
71 $actionMenu[] = $linkConf[2] . ' ' . htmlspecialchars($linkConf[0]);
72 $actionMenu[] = '</a>';
73 $actionMenu[] = '</li>';
74 }
75 $actionMenu[] = '</ul>';
76 return implode(LF, $actionMenu);
77 }
78
79 /**
80 * Gets the entries for the action menu
81 *
82 * @return array Array of action menu entries
83 */
84 protected function initializeActionEntries()
85 {
86 $backendUser = $this->getBackendUser();
87 $databaseConnection = $this->getDatabaseConnection();
88 $actions = array();
89 if ($backendUser->isAdmin()) {
90 $queryResource = $databaseConnection->exec_SELECTquery('*', 'sys_action', 'pid = 0 AND hidden=0', '', 'sys_action.sorting');
91 } else {
92 $groupList = 0;
93 if ($backendUser->groupList) {
94 $groupList = $backendUser->groupList;
95 }
96 $queryResource = $databaseConnection->exec_SELECT_mm_query(
97 'sys_action.*',
98 'sys_action',
99 'sys_action_asgr_mm',
100 'be_groups',
101 ' AND be_groups.uid IN (' . $groupList . ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
102 'sys_action.uid',
103 'sys_action.sorting'
104 );
105 }
106
107 if ($queryResource) {
108 while ($actionRow = $databaseConnection->sql_fetch_assoc($queryResource)) {
109 $actions[] = array(
110 $actionRow['title'],
111 BackendUtility::getModuleUrl('user_task') . '&SET[mode]=tasks&SET[function]=sys_action.TYPO3\\CMS\\SysAction\\ActionTask&show=' . $actionRow['uid'],
112 $this->iconFactory->getIconForRecord('sys_action', $actionRow, Icon::SIZE_SMALL)->render()
113 );
114 }
115 $databaseConnection->sql_free_result($queryResource);
116 }
117 $this->actionEntries = $actions;
118 }
119
120 /**
121 * This toolbar needs no additional attributes
122 *
123 * @return array
124 */
125 public function getAdditionalAttributes()
126 {
127 return array();
128 }
129
130 /**
131 * This item has a drop down
132 *
133 * @return bool
134 */
135 public function hasDropDown()
136 {
137 return true;
138 }
139
140 /**
141 * This toolbar is rendered if there are action entries, no further user restriction
142 *
143 * @return bool TRUE
144 */
145 public function checkAccess()
146 {
147 $result = false;
148 if (!empty($this->actionEntries)) {
149 $result = true;
150 }
151 return $result;
152 }
153
154 /**
155 * Position relative to others
156 *
157 * @return int
158 */
159 public function getIndex()
160 {
161 return 35;
162 }
163
164 /**
165 * Returns the current BE user.
166 *
167 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
168 */
169 protected function getBackendUser()
170 {
171 return $GLOBALS['BE_USER'];
172 }
173
174 /**
175 * Returns LanguageService
176 *
177 * @return \TYPO3\CMS\Lang\LanguageService
178 */
179 protected function getLanguageService()
180 {
181 return $GLOBALS['LANG'];
182 }
183
184 /**
185 * Return DatabaseConnection
186 *
187 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
188 */
189 protected function getDatabaseConnection()
190 {
191 return $GLOBALS['TYPO3_DB'];
192 }
193 }