‪TYPO3CMS  ‪main
AvatarViewHelper.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 
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
66 final class ‪AvatarViewHelper extends AbstractViewHelper
67 {
68  use CompileWithRenderStatic;
69 
75  protected ‪$escapeOutput = false;
76 
77  public function ‪initializeArguments(): void
78  {
79  $this->registerArgument('backendUser', 'int', 'uid of the backend user', false, 0);
80  $this->registerArgument('size', 'int', 'width and height of the image', false, 32);
81  $this->registerArgument('showIcon', 'bool', 'show the record icon as well', false, false);
82  }
83 
89  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
90  {
91  if ($arguments['backendUser'] > 0) {
92  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
93  $queryBuilder->getRestrictions()->removeAll();
94  $backendUser = $queryBuilder
95  ->select('*')
96  ->from('be_users')
97  ->where(
98  $queryBuilder->expr()->eq(
99  'uid',
100  $queryBuilder->createNamedParameter($arguments['backendUser'], ‪Connection::PARAM_INT)
101  )
102  )
103  ->executeQuery()
104  ->fetchAssociative();
105  } else {
106  $backendUser = ‪$GLOBALS['BE_USER']->user;
107  }
108  if ($backendUser === false) {
109  // no BE user can be retrieved from DB, probably deleted
110  return '';
111  }
112  $avatar = GeneralUtility::makeInstance(Avatar::class);
113  return $avatar->render($backendUser, $arguments['size'], $arguments['showIcon']);
114  }
115 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: AvatarViewHelper.php:73
‪TYPO3\CMS\Backend\Backend\Avatar\Avatar
Definition: Avatar.php:35
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper
Definition: AvatarViewHelper.php:67
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: AvatarViewHelper.php:87
‪TYPO3\CMS\Backend\ViewHelpers
Definition: AvatarViewHelper.php:18
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\initializeArguments
‪initializeArguments()
Definition: AvatarViewHelper.php:75
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52