‪TYPO3CMS  9.5
IfHasRoleViewHelper.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 
17 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
18 
62 class ‪IfHasRoleViewHelper extends AbstractConditionViewHelper
63 {
69  public function ‪initializeArguments()
70  {
71  parent::initializeArguments();
72 
73  $this->registerArgument('role', 'string', 'The usergroup (either the usergroup uid or its title).');
74  }
75 
82  protected static function ‪evaluateCondition($arguments = null)
83  {
84  $role = $arguments['role'];
85  if (!is_array(‪$GLOBALS['BE_USER']->userGroups)) {
86  return false;
87  }
88  if (is_numeric($role)) {
89  foreach (‪$GLOBALS['BE_USER']->userGroups as $userGroup) {
90  if ((int)$userGroup['uid'] === (int)$role) {
91  return true;
92  }
93  }
94  } else {
95  foreach (‪$GLOBALS['BE_USER']->userGroups as $userGroup) {
96  if ($userGroup['title'] === $role) {
97  return true;
98  }
99  }
100  }
101  return false;
102  }
103 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security
Definition: IfAuthenticatedViewHelper.php:2
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper\evaluateCondition
‪static bool evaluateCondition($arguments=null)
Definition: IfHasRoleViewHelper.php:82
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper
Definition: IfHasRoleViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper\initializeArguments
‪initializeArguments()
Definition: IfHasRoleViewHelper.php:69