* ``` * * @internal */ final class PermissionsViewHelper extends AbstractViewHelper { private const array MASKS = [1, 16, 2, 4, 8]; /** * As this ViewHelper renders HTML, the output must not be escaped. * * @var bool */ protected $escapeOutput = false; public function __construct( private readonly IconFactory $iconFactory, #[Autowire(service: 'cache.runtime')] private readonly FrontendInterface $cachePermissionLabels ) {} public function initializeArguments(): void { $this->registerArgument('permission', 'int', 'Current permission', true); $this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true); $this->registerArgument('pageId', 'int', 'Page ID to evaluate permission for', true); } public function render(): string { $icon = ''; foreach (self::MASKS as $mask) { if ($this->arguments['permission'] & $mask) { $iconIdentifier = 'actions-check'; $iconClass = 'text-success'; $mode = 'delete'; } else { $iconIdentifier = 'actions-close'; $iconClass = 'text-danger'; $mode = 'add'; } $label = $this->resolvePermissionLabel($mask); $icon .= '' . $this->iconFactory->getIcon($iconIdentifier, IconSize::SMALL)->render(SvgIconProvider::MARKUP_IDENTIFIER_INLINE) . ''; } return $icon; } private function resolvePermissionLabel(int $mask): string { $cacheIdentifier = 'beuser-viewhelper-permission_' . $mask; if (!$this->cachePermissionLabels->has($cacheIdentifier)) { $this->cachePermissionLabels->set($cacheIdentifier, htmlspecialchars($this->getLanguageService()->sL( 'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask, ))); } return $this->cachePermissionLabels->get($cacheIdentifier); } private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }