TYPO3 CMS  TYPO3_8-7
BackendUserActionController.php
Go to the documentation of this file.
1 <?php
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 
52  protected function initializeView(ViewInterface $view)
53  {
55  parent::initializeView($view);
56  if ($this->actionMethodName === 'indexAction'
57  || $this->actionMethodName === 'onlineAction'
58  || $this->actionMethodName === 'compareAction') {
59  $this->generateMenu();
60  $this->registerDocheaderButtons();
61  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
62  }
63  if ($view instanceof BackendTemplateView) {
64  $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
65  }
66  }
67 
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.xlf:backendUsers')
78  ],
79  'pages' => [
80  'controller' => 'BackendUserGroup',
81  'action' => 'index',
82  'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroupsMenu')
83  ],
84  'online' => [
85  'controller' => 'BackendUser',
86  'action' => 'online',
87  'label' => $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf: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 
117  protected function registerDocheaderButtons()
118  {
120  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
121  $currentRequest = $this->request;
122  $moduleName = $currentRequest->getPluginName();
123  $getVars = $this->request->getArguments();
124 
125  $extensionName = $currentRequest->getControllerExtensionName();
126  if (count($getVars) === 0) {
127  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
128  $getVars = ['id', 'M', $modulePrefix];
129  }
130  $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUsers');
131  if ($this->request->getControllerName() === 'BackendUser') {
132  if ($this->request->getControllerActionName() === 'index') {
133  $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser'));
134  $parameters = GeneralUtility::explodeUrl2Array('edit[be_users][0]=new&returnUrl=' . $returnUrl);
135  $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
136  $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral');
137  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
138  $addUserButton = $buttonBar->makeLinkButton()
139  ->setHref($addUserLink)
140  ->setTitle($title)
141  ->setIcon($icon);
142  $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
143  }
144  if ($this->request->getControllerActionName() === 'compare') {
145  $addUserLink = BackendUtility::getModuleUrl('system_BeuserTxBeuser');
146  $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack');
147  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
148  $addUserButton = $buttonBar->makeLinkButton()
149  ->setHref($addUserLink)
150  ->setTitle($title)
151  ->setIcon($icon);
152  $buttonBar->addButton($addUserButton, ButtonBar::BUTTON_POSITION_LEFT);
153  }
154  if ($this->request->getControllerActionName() === 'online') {
155  $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:onlineUsers');
156  }
157  }
158  if ($this->request->getControllerName() === 'BackendUserGroup') {
159  $shortcutName = $this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:backendUserGroupsMenu');
160  $returnUrl = rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser', [
161  'tx_beuser_system_beusertxbeuser' => [
162  'action' => 'index',
163  'controller' => 'BackendUserGroup'
164  ]
165  ]));
166  $parameters = GeneralUtility::explodeUrl2Array('edit[be_groups][0]=new&returnUrl=' . $returnUrl);
167  $addUserLink = BackendUtility::getModuleUrl('record_edit', $parameters);
168  $title = $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newRecordGeneral');
169  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL);
170  $addUserGroupButton = $buttonBar->makeLinkButton()
171  ->setHref($addUserLink)
172  ->setTitle($title)
173  ->setIcon($icon);
174  $buttonBar->addButton($addUserGroupButton, ButtonBar::BUTTON_POSITION_LEFT);
175  }
176  $shortcutButton = $buttonBar->makeShortcutButton()
177  ->setModuleName($moduleName)
178  ->setDisplayName($shortcutName)
179  ->setGetVariables($getVars);
180  $buttonBar->addButton($shortcutButton);
181  }
182 
191  protected function getHref($controller, $action, $parameters = [])
192  {
193  $uriBuilder = $this->objectManager->get(UriBuilder::class);
194  $uriBuilder->setRequest($this->request);
195  return $uriBuilder->reset()->uriFor($action, $parameters, $controller);
196  }
197 
201  protected function getBackendUserAuthentication()
202  {
203  return $GLOBALS['BE_USER'];
204  }
205 
209  protected function getLanguageService()
210  {
211  return $GLOBALS['LANG'];
212  }
213 }
static explodeUrl2Array($string, $multidim=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']