‪TYPO3CMS  10.4
AvatarViewHelper.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 
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24 
63 class ‪AvatarViewHelper extends AbstractViewHelper
64 {
65  use CompileWithRenderStatic;
66 
72  protected ‪$escapeOutput = false;
73 
77  public function ‪initializeArguments()
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 
92  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
93  {
94  if ($arguments['backendUser'] > 0) {
95  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
96  $queryBuilder->getRestrictions()->removeAll();
97  $backendUser = $queryBuilder
98  ->select('*')
99  ->from('be_users')
100  ->where(
101  $queryBuilder->expr()->eq(
102  'uid',
103  $queryBuilder->createNamedParameter($arguments['backendUser'], \PDO::PARAM_INT)
104  )
105  )
106  ->execute()
107  ->fetch();
108  } else {
109  $backendUser = ‪$GLOBALS['BE_USER']->user;
110  }
111  if ($backendUser === false) {
112  // no BE user can be retrieved from DB, probably deleted
113  return '';
114  }
115  $avatar = GeneralUtility::makeInstance(Avatar::class);
116  return $avatar->render($backendUser, $arguments['size'], $arguments['showIcon']);
117  }
118 }
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: AvatarViewHelper.php:90
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: AvatarViewHelper.php:70
‪TYPO3\CMS\Backend\Backend\Avatar\Avatar
Definition: Avatar.php:33
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper
Definition: AvatarViewHelper.php:64
‪TYPO3\CMS\Backend\ViewHelpers
Definition: ArrayBrowserViewHelper.php:18
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\initializeArguments
‪initializeArguments()
Definition: AvatarViewHelper.php:75
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46