TYPO3 CMS  TYPO3_8-7
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 
21 
29 {
31 
37  protected $escapeOutput = false;
38 
42  protected static $permissionLabels = [];
43 
47  public function initializeArguments()
48  {
49  parent::initializeArguments();
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 }
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
static translate($key, $extensionName=null, $arguments=null)