TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:03 +02:00
commit 61d66df078
65 changed files with 8311 additions and 0 deletions
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use TYPO3\CMS\Beuser\Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to get a value from an array by given key.
*
* ```
* <f:render
* partial="Permission/Ownername"
* arguments="{
* username: '{beuser:arrayElement(array:beUsers, key:data.row.perms_userid, subKey:\'username\')}'
* }"
* />
* ```
*
* @internal
*/
final class ArrayElementViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('array', 'array', 'Array to search in', true);
$this->registerArgument('key', 'string', 'Key to return its value', true);
$this->registerArgument('subKey', 'string', 'If result of key access is an array, subkey can be used to fetch an element from this again', false, '');
}
/**
* Return array element by key. Accessed values must be scalar (string, int, float or double)
*
* @throws Exception
*/
public function render(): string
{
$array = $this->arguments['array'];
$key = $this->arguments['key'];
$subKey = $this->arguments['subKey'];
$result = '';
if (isset($array[$key])) {
$result = $array[$key];
if (is_array($result) && $subKey && isset($result[$subKey])) {
$result = $result[$subKey];
}
}
if (!is_scalar($result)) {
throw new Exception('Only scalar return values (string, int, float or double) are supported.', 1382284105);
}
return (string)$result;
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to checks whether the given value is an array.
*
* @internal
*/
final class IsArrayViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('value', 'mixed', 'The variable being checked', true);
}
public function render(): bool
{
return is_array($this->arguments['value']);
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper to render MFA status information.
*
* ```
* <beuser:mfaStatus userUid="{backendUser.uid}" />
* ```
*
* @internal
*/
final class MfaStatusViewHelper extends AbstractTagBasedViewHelper
{
protected $tagName = 'span';
public function __construct(
private readonly MfaProviderRegistry $mfaProviderRegistry
) {
parent::__construct();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('userUid', 'int', 'The uid of the user to check', true);
}
public function render(): string
{
$userUid = (int)($this->arguments['userUid'] ?? 0);
if (!$userUid) {
return '';
}
$backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class);
$backendUser->enablecolumns = ['deleted' => true];
$backendUser->setBeUserByUid($userUid);
// Check if user has active providers
if (!$this->mfaProviderRegistry->hasActiveProviders($backendUser)) {
return '';
}
// Check locked providers
if ($this->mfaProviderRegistry->hasLockedProviders($backendUser)) {
$this->tag->addAttribute('class', 'badge badge-warning');
$this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:lockedMfaProviders')));
return $this->tag->render();
}
// Add mfa enabled label since we have active providers and non of them are locked
$this->tag->addAttribute('class', 'badge badge-info');
$this->tag->setContent(htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:mfaEnabled')));
return $this->tag->render();
}
private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to render a permission icon group (user / group / others) of the "Access" module,
* using native PHP instead of Fluid for performance reasons.
*
* ```
* <beuser:permissions permission="{data.row.perms_user}" scope="user" pageId="{data.row.uid}" />
* ```
*
* @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 .= '<button'
. ' aria-label="' . htmlspecialchars($label) . ', ' . htmlspecialchars($mode) . ', ' . htmlspecialchars($this->arguments['scope']) . '"'
. ' title="' . htmlspecialchars($label) . '"'
. ' data-page="' . htmlspecialchars((string)$this->arguments['pageId']) . '"'
. ' data-permissions="' . htmlspecialchars((string)$this->arguments['permission']) . '"'
. ' data-who="' . htmlspecialchars($this->arguments['scope']) . '"'
. ' data-bits="' . htmlspecialchars((string)$mask) . '"'
. ' data-mode="' . htmlspecialchars($mode) . '"'
. ' class="btn btn-default btn-icon btn-borderless change-permission ' . htmlspecialchars($iconClass) . '">'
. $this->iconFactory->getIcon($iconIdentifier, IconSize::SMALL)->render(SvgIconProvider::MARKUP_IDENTIFIER_INLINE)
. '</button>';
}
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'];
}
}
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper to display a sprite icon for a record (object).
*
* ```
* <beuser:spriteIconForRecord table="be_groups" object="{backendUserGroup}" />
* ```
*
* @internal
*/
final class SpriteIconForRecordViewHelper extends AbstractViewHelper
{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
public function __construct(
private readonly IconFactory $iconFactory
) {}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('table', 'string', '', true);
$this->registerArgument('object', 'object', '', true);
}
/**
* Displays spriteIcon for database table and object
*/
public function render(): string
{
$object = $this->arguments['object'];
$table = $this->arguments['table'];
if (!method_exists($object, 'getUid')) {
return '';
}
$row = [
'uid' => $object->getUid(),
'startTime' => false,
'endTime' => false,
];
if (method_exists($object, 'getIsDisabled')) {
$row['disable'] = $object->getIsDisabled();
}
if (method_exists($object, 'getHidden')) {
$row['hidden'] = $object->getHidden();
}
if (method_exists($object, 'getStartDateAndTime')) {
$row['startTime'] = $object->getStartDateAndTime();
}
if (method_exists($object, 'getEndDateAndTime')) {
$row['endTime'] = $object->getEndDateAndTime();
}
return $this->iconFactory->getIconForRecord($table, $row, IconSize::SMALL)->render();
}
}
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\ViewHelpers;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper to displays a 'SwitchUser' button to change the current backend user to the target backend user.
*
* ```
* <beuser:SwitchUser class="btn btn-default" backendUser="{backendUser}" />
* ```
*
* @internal
*/
final class SwitchUserViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'typo3-backend-switch-user';
public function __construct(
private readonly IconFactory $iconFactory
) {
parent::__construct();
}
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
}
public function render(): string
{
/** @var BackendUser $targetUser */
$targetUser = $this->arguments['backendUser'];
$currentUser = self::getBackendUserAuthentication();
if ((int)$targetUser->getUid() === (int)$currentUser->getUserId()
|| !$targetUser->isActive()
|| !$currentUser->isAdmin()
|| $currentUser->getOriginalUserIdWhenInSwitchUserMode() !== null
) {
$this->tag->setTagName('span');
$this->tag->addAttribute('class', $this->tag->getAttribute('class') . ' disabled');
$this->tag->addAttribute('disabled', 'disabled');
$this->tag->setContent($this->iconFactory->getIcon('empty-empty', IconSize::SMALL)->render());
} else {
$this->tag->addAttribute('title', self::getLanguageService()->sL('LLL:EXT:beuser/Resources/Private/Language/locallang.xlf:switchBackMode'));
$this->tag->addAttribute('targetUser', (string)$targetUser->getUid());
$this->tag->setContent($this->iconFactory->getIcon('actions-system-backend-user-switch', IconSize::SMALL)->render());
}
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
private static function getBackendUserAuthentication(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
private static function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}