‪TYPO3CMS  10.4
PermissionsViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22 
30 class ‪PermissionsViewHelper extends AbstractViewHelper
31 {
32  use CompileWithRenderStatic;
33 
39  protected ‪$escapeOutput = false;
40 
44  protected static ‪$permissionLabels = [];
45 
49  public function ‪initializeArguments()
50  {
51  $this->registerArgument('permission', 'int', 'Current permission', true);
52  $this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true);
53  $this->registerArgument('pageId', 'int', '', true);
54  }
55 
65  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
66  {
67  $masks = [1, 16, 2, 4, 8];
68 
69  if (empty(static::$permissionLabels)) {
70  foreach ($masks as $mask) {
71  static::$permissionLabels[$mask] = ‪LocalizationUtility::translate(
72  'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask,
73  'be_user'
74  );
75  }
76  }
77 
78  $icon = '';
79  foreach ($masks as $mask) {
80  if ($arguments['permission'] & $mask) {
81  $permissionClass = 'fa-check text-success';
82  $mode = 'delete';
83  } else {
84  $permissionClass = 'fa-times text-danger';
85  $mode = 'add';
86  }
87 
88  $label = static::$permissionLabels[$mask];
89  $icon .= '<button'
90  . ' aria-label="' . htmlspecialchars($label) . ', ' . htmlspecialchars($mode) . ', ' . htmlspecialchars($arguments['scope']) . '"'
91  . ' title="' . htmlspecialchars($label) . '"'
92  . ' data-toggle="tooltip"'
93  . ' data-page="' . htmlspecialchars($arguments['pageId']) . '"'
94  . ' data-permissions="' . htmlspecialchars($arguments['permission']) . '"'
95  . ' data-who="' . htmlspecialchars($arguments['scope']) . '"'
96  . ' data-bits="' . htmlspecialchars((string)$mask) . '"'
97  . ' data-mode="' . htmlspecialchars($mode) . '"'
98  . ' class="t3-icon btn-clear change-permission fa ' . htmlspecialchars($permissionClass) . '"></button>';
99  }
100 
101  return '<span id="' . htmlspecialchars($arguments['pageId'] . '_' . $arguments['scope']) . '">' . $icon . '</span>';
102  }
103 }
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\initializeArguments
‪initializeArguments()
Definition: PermissionsViewHelper.php:46
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Beuser\ViewHelpers
Definition: ArrayElementViewHelper.php:16
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper
Definition: PermissionsViewHelper.php:31
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: PermissionsViewHelper.php:37
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\$permissionLabels
‪static array $permissionLabels
Definition: PermissionsViewHelper.php:41
‪TYPO3\CMS\Beuser\ViewHelpers\PermissionsViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: PermissionsViewHelper.php:62