‪TYPO3CMS  10.4
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 
23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
26 
31 class ‪SwitchUserViewHelper extends AbstractViewHelper
32 {
33  use CompileWithRenderStatic;
34 
40  protected ‪$escapeOutput = false;
41 
45  public function ‪initializeArguments()
46  {
47  $this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
48  }
49 
59  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
60  {
61  $backendUser = $arguments['backendUser'];
62  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63  if ($backendUser->getUid() == ‪$GLOBALS['BE_USER']->user['uid'] || !$backendUser->isActive() || ‪$GLOBALS['BE_USER']->user['ses_backuserid']) {
64  return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', ‪Icon::SIZE_SMALL)->render() . '</span>';
65  }
66  $title = ‪LocalizationUtility::translate('switchBackMode', 'beuser') ?? '';
67  return '<a class="btn btn-default" href="' .
68  htmlspecialchars(GeneralUtility::linkThisScript(['SwitchUser' => $backendUser->getUid()])) .
69  '" target="_top" title="' . htmlspecialchars($title) . '">' .
70  $iconFactory->getIcon('actions-system-backend-user-switch', ‪Icon::SIZE_SMALL)->render() . '</a>';
71  }
72 }
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: SwitchUserViewHelper.php:38
‪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:32
‪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:33
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\initializeArguments
‪initializeArguments()
Definition: SwitchUserViewHelper.php:43
‪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
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: SwitchUserViewHelper.php:57
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46