|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\ViewHelpers; |
|
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\AbstractViewHelper; |
|
18
|
|
|
use \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
21
|
|
|
use \EWW\Dpf\Security\Security; |
|
22
|
|
|
|
|
23
|
|
|
class IsElementAllowedViewHelper extends AbstractViewHelper |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param array $arguments |
|
27
|
|
|
* @param \Closure $renderChildrenClosure |
|
28
|
|
|
* @param RenderingContextInterface $renderingContext |
|
29
|
|
|
* @return boolean |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
32
|
|
|
{ |
|
33
|
|
|
$roles = array(); |
|
34
|
|
|
if (key_exists('condition', $arguments)) { |
|
35
|
|
|
$roles = $arguments['condition']; |
|
36
|
|
|
if (!is_array($roles)) return FALSE; |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
40
|
|
|
/** @var Security $security */ |
|
41
|
|
|
$security = $objectManager->get(Security::class); |
|
42
|
|
|
$clientUserRole = $security->getUserRole(); |
|
43
|
|
|
|
|
44
|
|
|
if (empty($roles)) { |
|
45
|
|
|
return TRUE; |
|
|
|
|
|
|
46
|
|
|
} else { |
|
47
|
|
|
foreach ($roles as $role) { |
|
48
|
|
|
if ($role === $clientUserRole) return TRUE; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return FALSE; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function initializeArguments() |
|
56
|
|
|
{ |
|
57
|
|
|
parent::initializeArguments(); |
|
58
|
|
|
|
|
59
|
|
|
$this->registerArgument('condition', 'array', 'The controller to be active.', true); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
public function render() |
|
66
|
|
|
{ |
|
67
|
|
|
$condition = $this->arguments['condition']; |
|
68
|
|
|
|
|
69
|
|
|
return self::renderStatic( |
|
70
|
|
|
array('condition' => $condition), |
|
71
|
|
|
$this->buildRenderChildrenClosure(), |
|
72
|
|
|
$this->renderingContext |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: