TYPO3 CMS  TYPO3_7-6
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 
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  if ($view instanceof BackendTemplateView) {
65  $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
66  }
67  }
68 
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 
121  protected function registerDocheaderButtons()
122  {
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/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 
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 
205  protected function getBackendUserAuthentication()
206  {
207  return $GLOBALS['BE_USER'];
208  }
209 
213  protected function getLanguageService()
214  {
215  return $GLOBALS['LANG'];
216  }
217 }
static explodeUrl2Array($string, $multidim=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']