TYPO3 CMS  TYPO3_7-6
UserToolbarItem.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 
25 
30 {
34  protected $iconFactory;
35 
39  public function __construct()
40  {
41  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
42  }
43 
49  public function checkAccess()
50  {
51  return true;
52  }
53 
59  public function getItem()
60  {
61  $backendUser = $this->getBackendUser();
62  $languageService = $this->getLanguageService();
63 
65  $avatar = GeneralUtility::makeInstance(Avatar::class);
66  $icon = $avatar->render();
67 
68  $realName = $backendUser->user['realName'];
69  $username = $backendUser->user['username'];
70  $label = $realName ?: $username;
71  $title = $username;
72 
73  // Switch user mode
74  if ($backendUser->user['ses_backuserid']) {
75  $title = $languageService->getLL('switchtouser') . ': ' . $username;
76  $label = $languageService->getLL('switchtousershort') . ' ' . ($realName ? $realName . ' (' . $username . ')' : $username);
77  }
78 
79  $html = [];
80  $html[] = $icon;
81  $html[] = '<span title="' . htmlspecialchars($title) . '">';
82  $html[] = htmlspecialchars($label);
83  $html[] = '<span class="caret"></span></span>';
84 
85  return implode(LF, $html);
86  }
87 
93  public function getDropDown()
94  {
95  $backendUser = $this->getBackendUser();
96  $languageService = $this->getLanguageService();
97 
98  $dropdown = [];
99  $dropdown[] = '<ul class="dropdown-list">';
100 
102  $backendModuleRepository = GeneralUtility::makeInstance(BackendModuleRepository::class);
104  $userModuleMenu = $backendModuleRepository->findByModuleName('user');
105  if ($userModuleMenu != false && $userModuleMenu->getChildren()->count() > 0) {
106  foreach ($userModuleMenu->getChildren() as $module) {
108  $dropdown[] ='<li'
109  . ' id="' . htmlspecialchars($module->getName()) . '"'
110  . ' class="typo3-module-menu-item submodule mod-' . htmlspecialchars($module->getName()) . '" '
111  . ' data-modulename="' . htmlspecialchars($module->getName()) . '"'
112  . ' data-navigationcomponentid="' . htmlspecialchars($module->getNavigationComponentId()) . '"'
113  . ' data-navigationframescript="' . htmlspecialchars($module->getNavigationFrameScript()) . '"'
114  . ' data-navigationframescriptparameters="' . htmlspecialchars($module->getNavigationFrameScriptParameters()) . '"'
115  . '>';
116  $dropdown[] = '<a title="' . htmlspecialchars($module->getDescription()) . '" href="' . htmlspecialchars($module->getLink()) . '" class="dropdown-list-link modlink">';
117  $dropdown[] = '<span class="submodule-icon typo3-app-icon"><span><span>' . $module->getIcon() . '</span></span></span>';
118  $dropdown[] = '<span class="submodule-label">' . htmlspecialchars($module->getTitle()) . '</span>';
119  $dropdown[] = '</a>';
120  $dropdown[] = '</li>';
121  }
122  $dropdown[] = '<li class="divider"></li>';
123  }
124 
125  // Logout button
126  $buttonLabel = 'LLL:EXT:lang/locallang_core.xlf:' . ($backendUser->user['ses_backuserid'] ? 'buttons.exit' : 'buttons.logout');
127  $dropdown[] = '<li class="reset-dropdown">';
128  $dropdown[] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('logout')) . '" class="btn btn-danger pull-right" target="_top">';
129  $dropdown[] = $this->iconFactory->getIcon('actions-logout', Icon::SIZE_SMALL)->render('inline') . ' ';
130  $dropdown[] = $languageService->sL($buttonLabel, true);
131  $dropdown[] = '</a>';
132  $dropdown[] = '</li>';
133 
134  $dropdown[] = '</ul>';
135 
136  return implode(LF, $dropdown);
137  }
138 
144  public function getAdditionalAttributes()
145  {
146  $result = [];
147  if ($this->getBackendUser()->user['ses_backuserid']) {
148  $result['class'] = 'su-user';
149  }
150  return $result;
151  }
152 
158  public function hasDropDown()
159  {
160  return true;
161  }
162 
168  public function getIndex()
169  {
170  return 80;
171  }
172 
178  protected function getBackendUser()
179  {
180  return $GLOBALS['BE_USER'];
181  }
182 
188  protected function getLanguageService()
189  {
190  return $GLOBALS['LANG'];
191  }
192 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']