TYPO3  7.6
BackendUserActionController.php
Go to the documentation of this file.
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 
27 
32 {
38  protected $defaultViewObjectName = BackendTemplateView::class;
39 
45  protected $view;
46 
53  protected function initializeView(ViewInterface $view)
54  {
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 
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 
118  protected function registerDocheaderButtons()
119  {
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 
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 
202  protected function getBackendUserAuthentication()
203  {
204  return $GLOBALS['BE_USER'];
205  }
206 
210  protected function getLanguageService()
211  {
212  return $GLOBALS['LANG'];
213  }
214 }