‪TYPO3CMS  11.5
UsernameViewHelper.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 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22 
27 class ‪UsernameViewHelper extends AbstractViewHelper
28 {
29  use CompileWithRenderStatic;
30 
36  protected static ‪$usernameRuntimeCache = [];
37 
41  public function ‪initializeArguments()
42  {
43  $this->registerArgument('uid', 'int', 'Uid of the user', true);
44  }
45 
55  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
56  {
57  $uid = $arguments['uid'];
58  if (isset(static::$usernameRuntimeCache[$uid])) {
59  return static::$usernameRuntimeCache[$uid];
60  }
61 
62  $user = BackendUtility::getRecord('be_users', $uid);
63  static::$usernameRuntimeCache[$uid] = $user['username'] ?? '';
64  return static::$usernameRuntimeCache[$uid];
65  }
66 }
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: UsernameViewHelper.php:53
‪TYPO3\CMS\Belog\ViewHelpers
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\$usernameRuntimeCache
‪static array $usernameRuntimeCache
Definition: UsernameViewHelper.php:34
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\initializeArguments
‪initializeArguments()
Definition: UsernameViewHelper.php:39
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper
Definition: UsernameViewHelper.php:28