‪TYPO3CMS  9.5
SwitchUserViewHelper.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 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
30 class ‪SwitchUserViewHelper extends AbstractViewHelper
31 {
32  use CompileWithRenderStatic;
33 
39  protected ‪$escapeOutput = false;
40 
44  public function ‪initializeArguments()
45  {
46  $this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
47  }
48 
58  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
59  {
60  $backendUser = $arguments['backendUser'];
61  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
62  if ($backendUser->getUid() == ‪$GLOBALS['BE_USER']->user['uid'] || !$backendUser->isActive() || ‪$GLOBALS['BE_USER']->user['ses_backuserid']) {
63  return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', ‪Icon::SIZE_SMALL)->render() . '</span>';
64  }
65  $title = ‪LocalizationUtility::translate('switchBackMode', 'beuser');
66  return '<a class="btn btn-default" href="' .
67  htmlspecialchars(GeneralUtility::linkThisScript(['SwitchUser' => $backendUser->getUid()])) .
68  '" target="_top" title="' . htmlspecialchars($title) . '">' .
69  $iconFactory->getIcon('actions-system-backend-user-switch', ‪Icon::SIZE_SMALL)->render() . '</a>';
70  }
71 }
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: SwitchUserViewHelper.php:37
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper
Definition: SwitchUserViewHelper.php:31
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Beuser\ViewHelpers
Definition: ArrayElementViewHelper.php:2
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Beuser\ViewHelpers\SwitchUserViewHelper\initializeArguments
‪initializeArguments()
Definition: SwitchUserViewHelper.php:42
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪$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:56
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45