2 namespace TYPO3\CMS\Fluid\ViewHelpers\Security
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper
;
20 * This view helper implements an ifHasRole/else condition for FE users/groups.
24 * <code title="Basic usage">
25 * <f:security.ifHasRole role="Administrator">
26 * This is being shown in case the current FE user belongs to a FE usergroup (aka role) titled "Administrator" (case sensitive)
27 * </f:security.ifHasRole>
30 * Everything inside the <f:ifHasRole> tag is being displayed if the logged in FE user belongs to the specified role.
33 * <code title="Using the usergroup uid as role identifier">
34 * <f:security.ifHasRole role="1">
35 * This is being shown in case the current FE user belongs to a FE usergroup (aka role) with the uid "1"
36 * </f:security.ifHasRole>
39 * Everything inside the <f:ifHasRole> tag is being displayed if the logged in FE user belongs to the specified role.
42 * <code title="IfRole / then / else">
43 * <f:security.ifHasRole role="Administrator">
45 * This is being shown in case you have the role.
48 * This is being displayed in case you do not have the role.
50 * </f:security.ifHasRole>
53 * Everything inside the "then" tag is displayed if the logged in FE user belongs to the specified role.
54 * Otherwise, everything inside the "else"-tag is displayed.
59 class IfHasRoleViewHelper
extends AbstractConditionViewHelper
62 * Initializes the "role" argument.
63 * Renders <f:then> child if the current logged in FE user belongs to the specified role (aka usergroup)
64 * otherwise renders <f:else> child.
66 public function initializeArguments()
68 $this->registerArgument('role', 'string', 'The usergroup (either the usergroup uid or its title).');
72 * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality.
74 * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
77 protected static function evaluateCondition($arguments = null
)
79 $role = $arguments['role'];
80 if (!isset($GLOBALS['TSFE']) ||
!$GLOBALS['TSFE']->loginUser
) {
83 if (is_numeric($role)) {
84 return is_array($GLOBALS['TSFE']->fe_user
->groupData
['uid']) && in_array($role, $GLOBALS['TSFE']->fe_user
->groupData
['uid']);
86 return is_array($GLOBALS['TSFE']->fe_user
->groupData
['title']) && in_array($role, $GLOBALS['TSFE']->fe_user
->groupData
['title']);