[TASK] Use strict comparison for strings
[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\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\View\BackendTemplateView;
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 if ($view instanceof BackendTemplateView) {
65 $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
66 }
67 }
68
69 /**
70 * Generates the action menu
71 *
72 * @return void
73 */
74 protected function generateMenu()
75 {
76 $menuItems = [
77 'index' => [
78 'controller' => 'BackendUser',
79 'action' => 'index',
80 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUsers')
81 ],
82 'pages' => [
83 'controller' => 'BackendUserGroup',
84 'action' => 'index',
85 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUserGroupsMenu')
86 ],
87 'online' => [
88 'controller' => 'BackendUser',
89 'action' => 'online',
90 'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:onlineUsers')
91 ]
92 ];
93 $uriBuilder = $this->objectManager->get(UriBuilder::class);
94 $uriBuilder->setRequest($this->request);
95
96 $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
97 $menu->setIdentifier('BackendUserModuleMenu');
98
99 foreach ($menuItems as $menuItemConfig) {
100 if ($this->request->getControllerName() === $menuItemConfig['controller']) {
101 $isActive = $this->request->getControllerActionName() === $menuItemConfig['action'] ? true : false;
102 } else {
103 $isActive = false;
104 }
105 $menuItem = $menu->makeMenuItem()
106 ->setTitle($menuItemConfig['label'])
107 ->setHref($this->getHref($menuItemConfig['controller'], $menuItemConfig['action']))
108 ->setActive($isActive);
109 $menu->addMenuItem($menuItem);
110 }
111
112 $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
113 }
114
115 /**
116 * Registers the Icons into the docheader
117 *
118 * @return void
119 * @throws \InvalidArgumentException
120 */
121 protected function registerDocheaderButtons()
122 {
123 /** @var ButtonBar $buttonBar */
124 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
125 $currentRequest = $this->request;
126 $moduleName = $currentRequest->getPluginName();
127 $getVars = $this->request->getArguments();
128
129 $extensionName = $currentRequest->getControllerExtensionName();
130 if (count($getVars) === 0) {
131 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
132 $getVars = ['id', 'M', $modulePrefix];
133 }
134 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUsers');
135 if ($this->request->getControllerName() === 'BackendUser') {
136 if ($this->request->getControllerActionName() === 'index') {
137 $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser'));
138 $parameters = GeneralUtility::explodeUrl2Array('edit[be_users][0]=new&returnUrl=' . $returnUrl);
139 $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
140 $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral');
141 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
142 $addUserButton = $buttonBar->makeLinkButton()
143 ->setHref($addUserLink)
144 ->setTitle($title)
145 ->setIcon($icon);
146 $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
147 }
148 if ($this->request->getControllerActionName() === 'compare') {
149 $addUserLink = BackendUtility::getModuleUrl('system_BeuserTxBeuser');
150 $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack');
151 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
152 $addUserButton = $buttonBar->makeLinkButton()
153 ->setHref($addUserLink)
154 ->setTitle($title)
155 ->setIcon($icon);
156 $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
157 }
158 if ($this->request->getControllerActionName() === 'online') {
159 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:onlineUsers');
160 }
161 }
162 if ($this->request->getControllerName() === 'BackendUserGroup') {
163 $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xml:backendUserGroupsMenu');
164 $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser', [
165 'tx_beuser_system_beusertxbeuser' => [
166 'action' => 'index',
167 'controller' => 'BackendUserGroup'
168 ]
169 ]));
170 $parameters = GeneralUtility::explodeUrl2Array('edit[be_groups][0]=new&returnUrl=' . $returnUrl);
171 $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
172 $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral');
173 $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
174 $addUserGroupButton = $buttonBar->makeLinkButton()
175 ->setHref($addUserLink)
176 ->setTitle($title)
177 ->setIcon($icon);
178 $buttonBar->addButton($addUserGroupButton, ButtonBar::BUTTON_POSITION_LEFT);
179 }
180 $shortcutButton = $buttonBar->makeShortcutButton()
181 ->setModuleName($moduleName)
182 ->setDisplayName($shortcutName)
183 ->setGetVariables($getVars);
184 $buttonBar->addButton($shortcutButton);
185 }
186
187 /**
188 * Creates te URI for a backend action
189 *
190 * @param string $controller
191 * @param string $action
192 * @param array $parameters
193 * @return string
194 */
195 protected function getHref($controller, $action, $parameters = [])
196 {
197 $uriBuilder = $this->objectManager->get(UriBuilder::class);
198 $uriBuilder->setRequest($this->request);
199 return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
200 }
201
202 /**
203 * @return BackendUserAuthentication
204 */
205 protected function getBackendUserAuthentication()
206 {
207 return $GLOBALS['BE_USER'];
208 }
209
210 /**
211 * @return LanguageService
212 */
213 protected function getLanguageService()
214 {
215 return $GLOBALS['LANG'];
216 }
217 }