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