TYPO3 CMS  TYPO3_7-6
UsernameViewHelper.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 
20 
26 {
32  protected static $usernameRuntimeCache = [];
33 
40  public function render($uid)
41  {
42  return static::renderStatic(
43  [
44  'uid' => $uid
45  ],
47  $this->renderingContext
48  );
49  }
50 
59  {
60  $uid = $arguments['uid'];
61 
62  if (isset(static::$usernameRuntimeCache[$uid])) {
63  return htmlspecialchars(static::$usernameRuntimeCache[$uid]);
64  }
65 
66  $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
67  $backendUserRepository = $objectManager->get(\TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository::class);
69  $user = $backendUserRepository->findByUid($uid);
70  // $user may be NULL if user was deleted from DB, set it to empty string to always return a string
71  static::$usernameRuntimeCache[$uid] = ($user === null) ? '' : $user->getUserName();
72  return htmlspecialchars(static::$usernameRuntimeCache[$uid]);
73  }
74 }
$uid
Definition: server.php:38
static renderStatic(array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)