[FEATURE] Add Contexts for storing data access modes
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Security / IfAuthenticatedViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Security;
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 TYPO3\CMS\Core\Context\Context;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
20
21 /**
22 * This view helper implements an ifAuthenticated/else condition for FE users/groups.
23 *
24 * = Examples =
25 *
26 * <code title="Basic usage">
27 * <f:security.ifAuthenticated>
28 * This is being shown whenever a FE user is logged in
29 * </f:security.ifAuthenticated>
30 * </code>
31 * <output>
32 * Everything inside the <f:ifAuthenticated> tag is being displayed if you are authenticated with any FE user account.
33 * </output>
34 *
35 * <code title="IfAuthenticated / then / else">
36 * <f:security.ifAuthenticated>
37 * <f:then>
38 * This is being shown in case you have access.
39 * </f:then>
40 * <f:else>
41 * This is being displayed in case you do not have access.
42 * </f:else>
43 * </f:security.ifAuthenticated>
44 * </code>
45 * <output>
46 * Everything inside the "then" tag is displayed if you have access.
47 * Otherwise, everything inside the "else"-tag is displayed.
48 * </output>
49 *
50 * @api
51 */
52 class IfAuthenticatedViewHelper extends AbstractConditionViewHelper
53 {
54 /**
55 * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality.
56 *
57 * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
58 * @return bool
59 */
60 protected static function evaluateCondition($arguments = null)
61 {
62 return GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'id', 0) > 0;
63 }
64 }