TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:00 +02:00
commit f9941541b7
1178 changed files with 135377 additions and 0 deletions
@@ -0,0 +1,97 @@
<?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\Backend\Backend\ToolbarItems;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Backend\Backend\Bookmark\BookmarkService;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
/**
* Class to render the bookmark menu toolbar.
*
* @internal This class is a specific Backend implementation and is not considered part of the Public TYPO3 API.
*/
#[Autoconfigure(public: true)]
class BookmarkToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
private ServerRequestInterface $request;
public function __construct(
private readonly BookmarkService $bookmarkService,
private readonly BackendViewFactory $backendViewFactory,
) {}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
/**
* Checks whether the user has access to this toolbar item.
*/
public function checkAccess(): bool
{
return $this->bookmarkService->isEnabled();
}
/**
* Render bookmark icon.
*/
public function getItem(): string
{
$view = $this->backendViewFactory->create($this->request);
return $view->render('ToolbarItems/BookmarkToolbarItemItem');
}
/**
* This item has a drop-down.
*/
public function hasDropDown(): bool
{
return true;
}
/**
* Render drop-down content.
* The dropdown contains a custom element that fetches data via AJAX.
*/
public function getDropDown(): string
{
$view = $this->backendViewFactory->create($this->request);
return $view->render('ToolbarItems/BookmarkToolbarItemDropDown');
}
/**
* This toolbar item needs no additional attributes.
*/
public function getAdditionalAttributes(): array
{
return [];
}
/**
* Position relative to others.
*/
public function getIndex(): int
{
return 40;
}
}
@@ -0,0 +1,182 @@
<?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\Backend\Backend\ToolbarItems;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
/**
* Render cache clearing toolbar item.
* Adds a dropdown if there are more than one item to clear (usually for admins to render the flush all caches).
* The dropdown items can be manipulated using ModifyClearCacheActionsEvent.
*
* @phpstan-type CacheAction array{
* id: non-empty-string,
* endpoint: non-empty-string,
* iconIdentifier: non-empty-string,
* title: non-empty-string,
* description?: non-empty-string,
* severity?: 'notice'|'info'|'succcess'|'warning'|'error'|'danger',
* }
*/
#[Autoconfigure(public: true)]
class ClearCacheToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
/**
* @var list<CacheAction>
*/
protected array $cacheActions = [];
/**
* @var list<non-empty-string>
*/
protected array $optionValues = [];
private ServerRequestInterface $request;
public function __construct(
UriBuilder $uriBuilder,
EventDispatcherInterface $eventDispatcher,
private readonly BackendViewFactory $backendViewFactory,
) {
$isAdmin = $this->getBackendUser()->isAdmin();
$userTsConfig = $this->getBackendUser()->getTSConfig();
// Clear all page-related caches
if ($isAdmin || ($userTsConfig['options.']['clearCache.']['pages'] ?? false)) {
$this->cacheActions[] = [
'id' => 'pages',
'title' => 'core.cache:group.pages.label',
'description' => 'core.cache:group.pages.description',
'endpoint' => (string)$uriBuilder->buildUriFromRoute('ajax_clearcache_group_pages'),
'severity' => 'success',
'iconIdentifier' => 'actions-bolt-alt',
];
$this->optionValues[] = 'pages';
}
// Clearing of all caches is only shown if explicitly enabled via TSConfig
// or if BE-User is admin and the TSconfig explicitly disables the possibility for admins.
// This is useful for big production systems where admins accidentally could slow down the system.
if (($userTsConfig['options.']['clearCache.']['all'] ?? false)
|| ($isAdmin && (bool)($userTsConfig['options.']['clearCache.']['all'] ?? true))
) {
$this->cacheActions[] = [
'id' => 'all',
'title' => 'core.cache:group.all.label',
'description' => 'core.cache:group.all.description',
'endpoint' => (string)$uriBuilder->buildUriFromRoute('ajax_clearcache_group_all'),
'severity' => 'danger',
'iconIdentifier' => 'actions-bolt-alt',
];
$this->optionValues[] = 'all';
}
$event = new ModifyClearCacheActionsEvent($this->cacheActions, $this->optionValues);
$event = $eventDispatcher->dispatch($event);
$this->cacheActions = $event->getCacheActions();
$this->optionValues = $event->getCacheActionIdentifiers();
}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
/**
* Checks whether the user has access to this toolbar item.
*/
public function checkAccess(): bool
{
$backendUser = $this->getBackendUser();
if ($backendUser->isAdmin()) {
return true;
}
foreach ($this->optionValues as $value) {
if ($backendUser->getTSConfig()['options.']['clearCache.'][$value] ?? false) {
return true;
}
}
return false;
}
/**
* Render clear cache icon, based on the option if there is more than one icon or just one.
*/
public function getItem(): string
{
$view = $this->backendViewFactory->create($this->request);
if ($this->hasDropDown()) {
return $view->render('ToolbarItems/ClearCacheToolbarItem');
}
$cacheAction = end($this->cacheActions);
$view->assignMultiple([
'endpoint' => $cacheAction['endpoint'],
'title' => $cacheAction['title'],
'iconIdentifier' => $cacheAction['iconIdentifier'],
]);
return $view->render('ToolbarItems/ClearCacheToolbarItemSingle');
}
/**
* Render drop-down.
*/
public function getDropDown(): string
{
$view = $this->backendViewFactory->create($this->request);
$view->assign('cacheActions', $this->cacheActions);
return $view->render('ToolbarItems/ClearCacheToolbarItemDropDown');
}
/**
* No additional attributes needed.
*/
public function getAdditionalAttributes(): array
{
return [];
}
/**
* This item has a drop-down, if there is more than one cache action available for the current Backend user.
*/
public function hasDropDown(): bool
{
return count($this->cacheActions) > 1;
}
/**
* Position relative to others
*/
public function getIndex(): int
{
return 20;
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
@@ -0,0 +1,98 @@
<?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\Backend\Backend\ToolbarItems;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Module\ModuleProvider;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
/**
* Adds backend live search to the toolbar by adding JavaScript and adding an input search field
*/
class LiveSearchToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
private ServerRequestInterface $request;
public function __construct(
private readonly ModuleProvider $moduleProvider,
private readonly BackendViewFactory $backendViewFactory,
) {}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
/**
* Checks whether the user has access to this toolbar item.
* Live search depends on the records module and only available when that module is allowed.
*/
public function checkAccess(): bool
{
return $this->moduleProvider->accessGranted('records', $this->getBackendUser());
}
/**
* Render search field.
*/
public function getItem(): string
{
$view = $this->backendViewFactory->create($this->request);
return $view->render('ToolbarItems/LiveSearchToolbarItem');
}
/**
* This item needs additional attributes.
*/
public function getAdditionalAttributes(): array
{
return ['class' => 't3js-toolbar-item-search'];
}
/**
* This item has no drop-down.
*/
public function hasDropDown(): bool
{
return false;
}
/**
* No drop-down here.
*/
public function getDropDown(): string
{
return '';
}
/**
* Position relative to others, live search should be very right.
*/
public function getIndex(): int
{
return 10;
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
@@ -0,0 +1,352 @@
<?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\Backend\Backend\ToolbarItems;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent;
use TYPO3\CMS\Backend\Toolbar\InformationStatus;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Render system information toolbar item and drop-down.
* Provides some events for other extensions to add information.
*/
#[Autoconfigure(public: true)]
class SystemInformationToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
private ServerRequestInterface $request;
protected array $systemInformation = [];
protected InformationStatus $highestSeverity;
protected string $severityBadgeClass = '';
protected array $systemMessages = [];
protected int $systemMessageTotalCount = 0;
public function __construct(
private readonly EventDispatcherInterface $eventDispatcher,
private readonly Typo3Version $typo3Version,
private readonly BackendViewFactory $backendViewFactory,
) {
$this->highestSeverity = InformationStatus::INFO;
}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
/**
* Add a system message.
* This is a callback method for signal receivers.
*
* @param string $text The text to be displayed
* @param InformationStatus $status The status of this system message
* @param int $count Will be added to the total count
* @param string $module The associated module
* @param string $params Query string with additional parameters
*/
public function addSystemMessage($text, InformationStatus $status = InformationStatus::OK, $count = 0, $module = '', $params = ''): void
{
$this->systemMessageTotalCount += $count;
// define the severity for the badge
if ($status->isGreaterThan($this->highestSeverity)) {
$this->highestSeverity = $status;
}
$this->systemMessages[] = [
'module' => $module,
'params' => $params,
'count' => $count,
'status' => $status->value,
'text' => $text,
];
}
/**
* Add a system information.
* This is a callback method for signal receivers.
*
* @param string $title The title of this system information, typically a LLL:EXT:... label string
* @param string $value The associated value
* @param string $iconIdentifier The icon identifier
* @param InformationStatus $status The status of this system information
*/
public function addSystemInformation($title, $value, $iconIdentifier, InformationStatus $status = InformationStatus::NOTICE): void
{
$this->systemInformation[] = [
'title' => $title,
'value' => $value,
'iconIdentifier' => $iconIdentifier,
'status' => $status->value,
];
}
/**
* Checks whether the user has access to this toolbar item.
*/
public function checkAccess(): bool
{
return $this->getBackendUserAuthentication()->isAdmin();
}
/**
* Render system information dropdown.
*/
public function getItem(): string
{
$view = $this->backendViewFactory->create($this->request);
return $view->render('ToolbarItems/SystemInformationToolbarItem');
}
/**
* Render drop-down
*/
public function getDropDown(): string
{
if (!$this->checkAccess()) {
return '';
}
$this->collectInformation();
$view = $this->backendViewFactory->create($this->request);
$view->assignMultiple([
'messages' => $this->systemMessages,
'count' => $this->systemMessageTotalCount > 99 ? '99+' : $this->systemMessageTotalCount,
'severityBadgeClass' => $this->severityBadgeClass,
'systemInformation' => $this->systemInformation,
]);
return $view->render('ToolbarItems/SystemInformationDropDown');
}
/**
* No additional attributes needed.
*/
public function getAdditionalAttributes(): array
{
return [];
}
/**
* This item has a drop-down.
*/
public function hasDropDown(): bool
{
return true;
}
/**
* Position relative to others
*/
public function getIndex(): int
{
return 30;
}
/**
* Collect the information for the drop-down.
*/
protected function collectInformation(): void
{
$this->addTypo3Version();
$this->addInstallationMode();
$this->addWebServer();
$this->addPhpVersion();
$this->addDebugger();
$this->addDatabase();
$this->addApplicationContext();
$this->addGitRevision();
$this->addOperatingSystem();
$this->eventDispatcher->dispatch(new SystemInformationToolbarCollectorEvent($this));
$this->severityBadgeClass = $this->highestSeverity !== InformationStatus::NOTICE ? 'badge-' . $this->highestSeverity->value : '';
}
protected function addTypo3Version(): void
{
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.typo3-version',
'value' => $this->typo3Version->getVersion(),
'iconIdentifier' => 'information-typo3-version',
];
}
protected function addInstallationMode(): void
{
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.installationMethod',
'value' => Environment::isComposerMode()
? $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.installationMethod.composer')
: $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.installationMethod.classic'),
'iconIdentifier' => 'actions-package',
];
}
protected function addWebServer(): void
{
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.webserver',
'value' => $_SERVER['SERVER_SOFTWARE'] ?? '',
'iconIdentifier' => 'information-webserver',
];
}
protected function addPhpVersion(): void
{
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.phpversion',
'value' => PHP_VERSION,
'iconIdentifier' => 'information-php-version',
];
}
protected function addDebugger(): void
{
$knownDebuggers = ['xdebug', 'Zend Debugger'];
foreach ($knownDebuggers as $debugger) {
if (extension_loaded($debugger)) {
$debuggerVersion = phpversion($debugger) ?: '';
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.debugger',
'value' => sprintf('%s %s', $debugger, $debuggerVersion),
'iconIdentifier' => 'information-debugger',
];
}
}
}
protected function addDatabase(): void
{
foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
$serverVersion = '[' . $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.database.offline') . ']';
$success = true;
try {
$serverVersion = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName($connectionName)
->getPlatformServerVersion();
} catch (\Exception $exception) {
$success = false;
}
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.database',
'titleAddition' => $connectionName,
'value' => $serverVersion,
'status' => $success ? InformationStatus::NOTICE->value : InformationStatus::ERROR->value,
'iconIdentifier' => 'information-database',
];
}
}
protected function addApplicationContext(): void
{
$applicationContext = Environment::getContext();
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.applicationcontext',
'value' => (string)$applicationContext,
'status' => $applicationContext->isProduction() ? InformationStatus::NOTICE->value : InformationStatus::WARNING->value,
'iconIdentifier' => 'information-application-context',
];
}
/**
* Gets the current GIT revision and branch
*/
protected function addGitRevision(): void
{
if (!str_ends_with($this->typo3Version->getVersion(), '-dev') || $this->isFunctionDisabled('exec')) {
return;
}
// check if git exists
$returnCode = 0;
CommandUtility::exec('git --version', $_, $returnCode);
if ($returnCode !== 0) {
// git is not available
return;
}
$revision = CommandUtility::exec('git rev-parse --short HEAD');
$branch = CommandUtility::exec('git rev-parse --abbrev-ref HEAD');
if ($revision === false || $branch === false) {
return;
}
$revision = trim($revision);
$branch = trim($branch);
if ($revision !== '' && $branch !== '') {
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.gitrevision',
'value' => sprintf('%s [%s]', $revision, $branch),
'iconIdentifier' => 'information-git',
];
}
}
/**
* Gets the system kernel and version
*/
protected function addOperatingSystem(): void
{
switch (PHP_OS_FAMILY) {
case 'Linux':
$icon = 'linux';
break;
case 'Darwin':
$icon = 'apple';
break;
case 'Windows':
$icon = 'windows';
break;
default:
$icon = 'unknown';
}
$this->systemInformation[] = [
'title' => 'LLL:EXT:backend/Resources/Private/Language/locallang_toolbar.xlf:toolbarItems.sysinfo.operatingsystem',
'value' => PHP_OS . ' ' . php_uname('r'),
'iconIdentifier' => 'information-os-' . $icon,
];
}
/**
* Check if the given PHP function is disabled in the system.
*/
protected function isFunctionDisabled(string $functionName): bool
{
$disabledFunctions = GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'));
if (!empty($disabledFunctions)) {
return in_array($functionName, $disabledFunctions, true);
}
return false;
}
protected function getBackendUserAuthentication(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
@@ -0,0 +1,196 @@
<?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\Backend\Backend\ToolbarItems;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Backend\ColorScheme;
use TYPO3\CMS\Backend\Module\ModuleProvider;
use TYPO3\CMS\Backend\Toolbar\RequestAwareToolbarItemInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
use TYPO3\CMS\Backend\View\BackendViewFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* User toolbar item and drop-down.
*
* @internal This class is a specific Backend implementation and is not considered part of the Public TYPO3 API.
*/
class UserToolbarItem implements ToolbarItemInterface, RequestAwareToolbarItemInterface
{
private ServerRequestInterface $request;
public function __construct(
private readonly ModuleProvider $moduleProvider,
private readonly BackendViewFactory $backendViewFactory,
) {}
public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
/**
* Item is always enabled.
*/
public function checkAccess(): bool
{
return true;
}
/**
* Render username and an icon.
*/
public function getItem(): string
{
$backendUser = $this->getBackendUser();
$view = $this->backendViewFactory->create($this->request);
$view->assignMultiple([
'currentUser' => $backendUser->user,
'switchUserMode' => (int)$backendUser->getOriginalUserIdWhenInSwitchUserMode(),
]);
return $view->render('ToolbarItems/UserToolbarItem');
}
/**
* Render drop-down content.
*/
public function getDropDown(): string
{
$backendUser = $this->getBackendUser();
$mostRecentUsers = [];
if ($backendUser->isAdmin()
&& $backendUser->getOriginalUserIdWhenInSwitchUserMode() === null
&& isset($backendUser->uc['recentSwitchedToUsers'])
&& is_array($backendUser->uc['recentSwitchedToUsers'])
) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
$result = $queryBuilder
->select('uid', 'username', 'realName')
->from('be_users')
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($backendUser->uc['recentSwitchedToUsers'], Connection::PARAM_INT_ARRAY))
)->executeQuery();
// Flip the array to have a "sorted" list of items
$mostRecentUsers = array_flip($backendUser->uc['recentSwitchedToUsers']);
while ($row = $result->fetchAssociative()) {
$mostRecentUsers[$row['uid']] = $row;
}
// Remove any item that is not an array (means, the stored uid is not available anymore)
$mostRecentUsers = array_filter($mostRecentUsers, is_array(...));
$availableUsers = array_keys($mostRecentUsers);
if (!empty(array_diff($backendUser->uc['recentSwitchedToUsers'], $availableUsers))) {
$backendUser->uc['recentSwitchedToUsers'] = $availableUsers;
$backendUser->writeUC();
}
}
$modules = null;
if ($userModule = $this->moduleProvider->getModuleForMenu('user', $backendUser)) {
$modules = $userModule->getSubModules();
}
$helpModules = null;
if ($helpModule = $this->moduleProvider->getModuleForMenu('help', $this->getBackendUser())) {
$helpModules = $helpModule->getSubModules();
}
$view = $this->backendViewFactory->create($this->request);
$view->assignMultiple([
'modules' => $modules,
'helpModules' => $helpModules,
'switchUserMode' => $this->getBackendUser()->getOriginalUserIdWhenInSwitchUserMode() !== null,
'recentUsers' => $mostRecentUsers,
'colorSchemeSwitchEnabled' => $this->getColorSchemeSwitchEnabled(),
'activeColorScheme' => $backendUser->uc['colorScheme'] ?? 'auto',
'colorSchemes' => $this->getColorSchemes(),
]);
return $view->render('ToolbarItems/UserToolbarItemDropDown');
}
/**
* Returns an additional class if user is in "switch user" mode.
*/
public function getAdditionalAttributes(): array
{
$result = [
'class' => 'toolbar-item-user',
];
if ($this->getBackendUser()->getOriginalUserIdWhenInSwitchUserMode()) {
$result['class'] .= ' su-user';
}
return $result;
}
/**
* This item has a drop-down.
*/
public function hasDropDown(): bool
{
return true;
}
/**
* Position relative to others.
*/
public function getIndex(): int
{
return 90;
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
protected function getColorSchemeSwitchEnabled(): bool
{
$backendUser = $this->getBackendUser();
$userTS = $backendUser->getTSConfig();
return !isset($userTS['setup.']['fields.']['colorScheme.']['disabled']) || $userTS['setup.']['fields.']['colorScheme.']['disabled'] !== '1';
}
protected function getColorSchemes(): array
{
$schemes = [];
foreach (ColorScheme::cases() as $scheme) {
$schemeItem = [
'label' => $this->getLanguageService()->sL($scheme->getLabel()),
'value' => $scheme->value,
'icon' => $scheme->getIcon(),
];
$schemes[] = $schemeItem;
}
return $schemes;
}
}