‪TYPO3CMS  9.5
AvatarViewHelper.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 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
62 class ‪AvatarViewHelper extends AbstractViewHelper
63 {
64  use CompileWithRenderStatic;
65 
71  protected ‪$escapeOutput = false;
72 
76  public function ‪initializeArguments()
77  {
78  $this->registerArgument('backendUser', 'int', 'uid of the backend user', false, 0);
79  $this->registerArgument('size', 'int', 'width and height of the image', false, 32);
80  $this->registerArgument('showIcon', 'bool', 'show the record icon as well', false, false);
81  }
82 
91  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
92  {
93  if ($arguments['backendUser'] > 0) {
94  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
95  $queryBuilder->getRestrictions()->removeAll();
96  $backendUser = $queryBuilder
97  ->select('*')
98  ->from('be_users')
99  ->where(
100  $queryBuilder->expr()->eq(
101  'uid',
102  $queryBuilder->createNamedParameter($arguments['backendUser'], \PDO::PARAM_INT)
103  )
104  )
105  ->execute()
106  ->fetch();
107  } else {
108  $backendUser = ‪$GLOBALS['BE_USER']->user;
109  }
110  if ($backendUser === false) {
111  // no BE user can be retrieved from DB, probably deleted
112  return '';
113  }
114  $avatar = GeneralUtility::makeInstance(Avatar::class);
115  return $avatar->render($backendUser, $arguments['size'], $arguments['showIcon']);
116  }
117 }
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: AvatarViewHelper.php:89
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: AvatarViewHelper.php:69
‪TYPO3\CMS\Backend\Backend\Avatar\Avatar
Definition: Avatar.php:33
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper
Definition: AvatarViewHelper.php:63
‪TYPO3\CMS\Backend\ViewHelpers
Definition: AvatarViewHelper.php:2
‪TYPO3\CMS\Backend\ViewHelpers\AvatarViewHelper\initializeArguments
‪initializeArguments()
Definition: AvatarViewHelper.php:74
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45