‪TYPO3CMS  11.5
SwitchUserViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
32 class ‪SwitchUserViewHelper extends AbstractViewHelper
33 {
34  use CompileWithRenderStatic;
35 
41  protected ‪$escapeOutput = false;
42 
46  public function ‪initializeArguments()
47  {
48  $this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
49  }
50 
60  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
61  {
62  $targetUser = $arguments['backendUser'];
64  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
65 
66  if ((int)$targetUser->getUid() === (int)($currentUser->user[$currentUser->userid_column] ?? 0)
67  || !$targetUser->isActive()
68  || !$currentUser->isAdmin()
69  || $currentUser->getOriginalUserIdWhenInSwitchUserMode() !== null
70  ) {
71  return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', ‪Icon::SIZE_SMALL)->render() . '</span>';
72  }
73 
74  return '
75  <typo3-backend-switch-user targetUser="' . htmlspecialchars((string)$targetUser->getUid()) . '">
76  <button type="button" class="btn btn-default" title="' . htmlspecialchars(‪LocalizationUtility::translate('switchBackMode', 'beuser') ?? '') . '">'
77  . $iconFactory->getIcon('actions-system-backend-user-switch', ‪Icon::SIZE_SMALL)->render() .
78  '</button>
79  </typo3-switch-user-button>';
80  }
81 
83  {
84  return ‪$GLOBALS['BE_USER'];
85  }
86 }
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: SwitchUserViewHelper.php:39
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper
Definition: SwitchUserViewHelper.php:33
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Beuser\ViewHelpers
Definition: ArrayElementViewHelper.php:16
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\initializeArguments
‪initializeArguments()
Definition: SwitchUserViewHelper.php:44
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: SwitchUserViewHelper.php:58
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\getBackendUserAuthentication
‪static getBackendUserAuthentication()
Definition: SwitchUserViewHelper.php:80