` tag) for a given backend user. * If the given backend user hasn't added a custom avatar yet, a default one is used. * * ``` * * ``` * * @see https://docs.typo3.org/permalink/t3viewhelper:typo3-backend-avatar */ final class AvatarViewHelper extends AbstractViewHelper { /** * As this ViewHelper renders HTML, the output must not be escaped. * * @var bool */ protected $escapeOutput = false; public function __construct( private readonly ConnectionPool $connectionPool, private readonly Avatar $avatar ) {} public function initializeArguments(): void { $this->registerArgument('backendUser', 'int', 'uid of the backend user', false, 0); $this->registerArgument('size', 'int', 'width and height of the image', false, 32); $this->registerArgument('showIcon', 'bool', 'show the record icon as well', false, false); } /** * Resolve user avatar from a given backend user id. */ public function render(): string { if ($this->arguments['backendUser'] > 0) { $queryBuilder = $this->connectionPool->getQueryBuilderForTable('be_users'); $queryBuilder->getRestrictions()->removeAll(); $backendUser = $queryBuilder ->select('*') ->from('be_users') ->where( $queryBuilder->expr()->eq( 'uid', $queryBuilder->createNamedParameter($this->arguments['backendUser'], Connection::PARAM_INT) ) ) ->executeQuery() ->fetchAssociative(); } else { $backendUser = $GLOBALS['BE_USER']->user; } if ($backendUser === false) { // no BE user can be retrieved from DB, probably deleted return ''; } return $this->avatar->render($backendUser, $this->arguments['size'], $this->arguments['showIcon']); } }