‪TYPO3CMS  9.5
PermissionsViewHelper.php
Go to the documentation of this file.
1 <?php
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 
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
21 
29 class ‪PermissionsViewHelper extends AbstractViewHelper
30 {
31  use CompileWithRenderStatic;
32 
38  protected ‪$escapeOutput = false;
39 
43  protected static ‪$permissionLabels = [];
44 
48  public function ‪initializeArguments()
49  {
50  $this->registerArgument('permission', 'int', 'Current permission', true);
51  $this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true);
52  $this->registerArgument('pageId', 'int', '', true);
53  }
54 
64  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
65  {
66  $masks = [1, 16, 2, 4, 8];
67 
68  if (empty(static::$permissionLabels)) {
69  foreach ($masks as $mask) {
70  static::$permissionLabels[$mask] = ‪LocalizationUtility::translate(
71  'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask,
72  'be_user'
73  );
74  }
75  }
76 
77  $icon = '';
78  foreach ($masks as $mask) {
79  if ($arguments['permission'] & $mask) {
80  $permissionClass = 'fa-check text-success';
81  $mode = 'delete';
82  } else {
83  $permissionClass = 'fa-times text-danger';
84  $mode = 'add';
85  }
86 
87  $label = static::$permissionLabels[$mask];
88  $icon .= '<span style="cursor:pointer"'
89  . ' title="' . htmlspecialchars($label) . '"'
90  . ' data-toggle="tooltip"'
91  . ' data-page="' . htmlspecialchars($arguments['pageId']) . '"'
92  . ' data-permissions="' . htmlspecialchars($arguments['permission']) . '"'
93  . ' data-who="' . htmlspecialchars($arguments['scope']) . '"'
94  . ' data-bits="' . htmlspecialchars($mask) . '"'
95  . ' data-mode="' . htmlspecialchars($mode) . '"'
96  . ' class="t3-icon change-permission fa ' . htmlspecialchars($permissionClass) . '"></span>';
97  }
98 
99  return '<span id="' . htmlspecialchars($arguments['pageId'] . '_' . $arguments['scope']) . '">' . $icon . '</span>';
100  }
101 }
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\initializeArguments
‪initializeArguments()
Definition: PermissionsViewHelper.php:45
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Beuser\ViewHelpers
Definition: ArrayElementViewHelper.php:2
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper
Definition: PermissionsViewHelper.php:30
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: PermissionsViewHelper.php:36
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\$permissionLabels
‪static array $permissionLabels
Definition: PermissionsViewHelper.php:40
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: PermissionsViewHelper.php:61