[BUGFIX] Supply returnURL to EXT:beuser usergroups
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / PermissionsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\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 TYPO3\CMS\Extbase\Utility\LocalizationUtility;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
21
22 /**
23 * Render permission icon group (user / group / others) of the "Access" module.
24 *
25 * Most of that could be done in fluid directly, but this view helper
26 * is much better performance wise.
27 */
28 class PermissionsViewHelper extends AbstractViewHelper implements CompilableInterface
29 {
30 /**
31 * @var array Cached labels for a single permission mask like "Delete page"
32 */
33 protected static $permissionLabels = array();
34
35 /**
36 * Return permissions.
37 *
38 * @param int $permission Current permission
39 * @param string $scope "user" / "group" / "everybody"
40 * @param int $pageId
41 * @return string
42 */
43 public function render($permission, $scope, $pageId)
44 {
45 return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
46 }
47
48 /**
49 * Implementing CompilableInterface suppresses object instantiation of this view helper
50 *
51 * @param array $arguments
52 * @param \Closure $renderChildrenClosure
53 * @param RenderingContextInterface $renderingContext
54 * @return string
55 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
56 */
57 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
58 {
59 $masks = array(1, 16, 2, 4, 8);
60
61 if (empty(static::$permissionLabels)) {
62 foreach ($masks as $mask) {
63 static::$permissionLabels[$mask] = LocalizationUtility::translate(
64 'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask,
65 'be_user'
66 );
67 }
68 }
69
70 $icon = '';
71 foreach ($masks as $mask) {
72 if ($arguments['permission'] & $mask) {
73 $permissionClass = 'fa-check text-success';
74 $mode = 'delete';
75 } else {
76 $permissionClass = 'fa-times text-danger';
77 $mode = 'add';
78 }
79 $icon .= '<span style="cursor:pointer"'
80 . ' title="' . htmlspecialchars(static::$permissionLabels[$mask]) . '"'
81 . ' data-page="' . $arguments['pageId'] . '"'
82 . ' data-permissions="' . $arguments['permission'] . '"'
83 . ' data-who="' . $arguments['scope'] . '"'
84 . ' data-bits="' . $mask . '"'
85 . ' data-mode="' . $mode . '"'
86 . ' class="t3-icon change-permission fa ' . $permissionClass . '"></span>';
87 }
88
89 return '<span id="' . $arguments['pageId'] . '_' . $arguments['scope'] . '">' . $icon . '</span>';
90 }
91 }