‪TYPO3CMS  ‪main
UsernameViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24 
30 final class ‪UsernameViewHelper extends AbstractViewHelper
31 {
32  use CompileWithRenderStatic;
33 
37  protected static array ‪$usernameRuntimeCache = [];
38 
42  public function ‪initializeArguments(): void
43  {
44  $this->registerArgument('uid', 'int', 'Uid of the user', true);
45  }
46 
52  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
53  {
54  ‪$uid = $arguments['uid'];
55  if (isset(self::$usernameRuntimeCache[‪$uid])) {
56  return self::$usernameRuntimeCache[‪$uid];
57  }
58  $user = BackendUtility::getRecord('be_users', ‪$uid);
59  self::$usernameRuntimeCache[‪$uid] = $user['username'] ?? '';
60  return self::$usernameRuntimeCache[‪$uid];
61  }
62 }
‪TYPO3\CMS\Belog\ViewHelpers
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\$usernameRuntimeCache
‪static array $usernameRuntimeCache
Definition: UsernameViewHelper.php:36
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: UsernameViewHelper.php:51
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper\initializeArguments
‪initializeArguments()
Definition: UsernameViewHelper.php:41
‪TYPO3\CMS\Belog\ViewHelpers\UsernameViewHelper
Definition: UsernameViewHelper.php:31