[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Controller / BackendUserActionController.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Controller;
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\Template\Components\ButtonBar;
18 use TYPO3\CMS\Backend\View\BackendTemplateView;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
24 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
25 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
26 use TYPO3\CMS\Lang\LanguageService;
27
28 /**
29 * Backend module user/group action controller
30 */
31 class BackendUserActionController extends ActionController
32 {
33 /**
34 * Backend Template Container
35 *
36 * @var string
37 */
38 protected $defaultViewObjectName = BackendTemplateView::class;
39
40 /**
41 * BackendTemplateContainer
42 *
43 * @var BackendTemplateView
44 */
45 protected $view;
46
47 /**
48 * Set up the doc header properly here
49 *
50 * @param ViewInterface $view
51 * @return void
52 */
53 protected function initializeView(ViewInterface $view)
54 {
55 /** @var BackendTemplateView $view */
56 parent::initializeView($view);
57 if ($this->actionMethodName == 'indexAction'
58 || $this->actionMethodName == 'onlineAction'
59 || $this->actionMethodName == 'compareAction') {
60 $this->generateMenu();
61 $this->registerDocheaderButtons();
62 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
63 }
64 }
65
66 /**
67 * Generates the action menu
68 *
69 * @return void
70 */
71 protected function generateMenu()
72 {
73 $menuItems = [
74 'index' => [
75 'controller' => 'BackendUser',
76 'action' => 'index',
77 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUsers')
78 ],
79 'pages' => [
80 'controller' => 'BackendUserGroup',
81 'action' => 'index',
82 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUserGroupsMenu')
83 ],
84 'online' => [
85 'controller' => 'BackendUser',
86 'action' => 'online',
87 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:onlineUsers')
88 ]
89 ];
90 $uriBuilder = $this->objectManager->get(UriBuilder::class);
91 $uriBuilder->setRequest($this->request);
92
93 $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
94 $menu->setIdentifier('BackendUserModuleMenu');
95
96 foreach ($menuItems as $menuItemConfig) {
97 if ($this->request->getControllerName() === $menuItemConfig['controller']) {
98 $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
99 } else {
100 $isActive = false;
101 }
102 $menuItem = $menu->makeMenuItem()
103 ->setTitle($menuItemConfig['label'])
104 ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
105 ->setActive($isActive);
106 $menu->addMenuItem($menuItem);
107 }
108
109 $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
110 }
111
112 /**
113 * Registers the Icons into the docheader
114 *
115 * @return void
116 * @throws \InvalidArgumentException
117 */
118 protected function registerDocheaderButtons()
119 {
120 /** @var ButtonBar $buttonBar */
121 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
122 $currentRequest = $this->request;
123 $moduleName = $currentRequest->getPluginName();
124 $getVars = $this->request->getArguments();
125
126 $extensionName = $currentRequest->getControllerExtensionName();
127 if (count($getVars) === 0) {
128 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
129 $getVars = array('id', 'M', $modulePrefix);
130 }
131 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUsers');
132 if ($this->request->getControllerName() === 'BackendUser') {
133 if ($this->request->getControllerActionName() === 'index') {
134 $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser'));
135 $parameters = GeneralUtility::explodeUrl2Array('edit[be_users][0]=new&returnUrl=' . $returnUrl);
136 $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
137 $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral', true);
138 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
139 $addUserButton = $buttonBar->makeLinkButton()
140 ->setHref($addUserLink)
141 ->setTitle($title)
142 ->setIcon($icon);
143 $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
144 }
145 if ($this->request->getControllerActionName() === 'compare') {
146 $addUserLink = BackendUtility::getModuleUrl('system_BeuserTxBeuser');
147 $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true);
148 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
149 $addUserButton = $buttonBar->makeLinkButton()
150 ->setHref($addUserLink)
151 ->setTitle($title)
152 ->setIcon($icon);
153 $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
154 }
155 if ($this->request->getControllerActionName() === 'online') {
156 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:onlineUsers');
157 }
158 }
159 if ($this->request->getControllerName() === 'BackendUserGroup') {
160 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUserGroupsMenu');
161 $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser', array(
162 'tx_beuser_system_beusertxbeuser' => array(
163 'action' => 'index',
164 'controller' => 'BackendUserGroup'
165 )
166 )));
167 $parameters = GeneralUtility::explodeUrl2Array('edit[be_groups][0]=new&returnUrl=' . $returnUrl);
168 $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
169 $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral', true);
170 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
171 $addUserGroupButton = $buttonBar->makeLinkButton()
172 ->setHref($addUserLink)
173 ->setTitle($title)
174 ->setIcon($icon);
175 $buttonBar->addButton($addUserGroupButton, ButtonBar::BUTTON_POSITION_LEFT);
176 }
177 $shortcutButton = $buttonBar->makeShortcutButton()
178 ->setModuleName($moduleName)
179 ->setDisplayName($shortcutName)
180 ->setGetVariables($getVars);
181 $buttonBar->addButton($shortcutButton);
182 }
183
184 /**
185 * Creates te URI for a backend action
186 *
187 * @param string $controller
188 * @param string $action
189 * @param array $parameters
190 * @return string
191 */
192 protected function getHref($controller, $action, $parameters = [])
193 {
194 $uriBuilder = $this->objectManager->get(UriBuilder::class);
195 $uriBuilder->setRequest($this->request);
196 return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
197 }
198
199 /**
200 * @return BackendUserAuthentication
201 */
202 protected function getBackendUserAuthentication()
203 {
204 return $GLOBALS['BE_USER'];
205 }
206
207 /**
208 * @return LanguageService
209 */
210 protected function getLanguageService()
211 {
212 return $GLOBALS['LANG'];
213 }
214 }