TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -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\Backend\Form\FieldInformation;
|
||||
|
||||
use TYPO3\CMS\Backend\Form\AbstractNode;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
|
||||
/**
|
||||
* This field information node is used in be_user admin field
|
||||
* to show some additional information if the edited user
|
||||
* is a system maintainer or becomes one if togging the admin flag.
|
||||
*/
|
||||
class AdminIsSystemMaintainer extends AbstractNode
|
||||
{
|
||||
/**
|
||||
* Handler for single nodes
|
||||
*
|
||||
* @return array As defined in initializeResultArray() of AbstractNode
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
if ($this->data['tableName'] !== 'be_users' || $this->data['fieldName'] !== 'admin') {
|
||||
throw new \RuntimeException(
|
||||
'The adminIsSystemMaintainer field information can be used for admin field in be_users table only',
|
||||
1537273550
|
||||
);
|
||||
}
|
||||
|
||||
$resultArray = $this->initializeResultArray();
|
||||
if ($this->data['command'] === 'new') {
|
||||
// Early return on 'new' records - nothing we can do here
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
$systemMaintainers = array_map(intval(...), $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemMaintainers'] ?? []);
|
||||
$isTargetUserInSystemMaintainerList = in_array((int)$this->data['vanillaUid'], $systemMaintainers, true);
|
||||
if ($isTargetUserInSystemMaintainerList) {
|
||||
$languageService = $this->getLanguageService();
|
||||
$isTargetUserAdmin = (int)$this->data['databaseRow']['admin'] === 1;
|
||||
if ($isTargetUserAdmin) {
|
||||
// User is a system maintainer
|
||||
$fieldInformationText = '<strong>' . htmlspecialchars($languageService->sL(
|
||||
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.beUser.admin.information.userIsSystemMaintainer'
|
||||
)) . '</strong>';
|
||||
} else {
|
||||
// User is currently not an admin, but set as system maintainer (in-effective).
|
||||
// If admin field is set to 1, the user is therefore system maintainer again.
|
||||
$fieldInformationText = '<strong>' . htmlspecialchars($languageService->sL(
|
||||
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.beUser.admin.information.userWillBecomeSystemMaintainer'
|
||||
)) . '</strong>';
|
||||
}
|
||||
$resultArray['html'] = $fieldInformationText;
|
||||
}
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
protected function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
|
||||
protected function getBackendUser(): BackendUserAuthentication
|
||||
{
|
||||
return $GLOBALS['BE_USER'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?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\Form\FieldInformation;
|
||||
|
||||
use TYPO3\CMS\Backend\Form\AbstractNode;
|
||||
use TYPO3\CMS\Backend\View\BackendLayoutView;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
|
||||
/**
|
||||
* This field information node is used for the pages backend_layout
|
||||
* field to inform about a possible backend layout, inherited form
|
||||
* a parent page.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BackendLayoutFromParentPage extends AbstractNode
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BackendLayoutView $backendLayoutView,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handler for single nodes
|
||||
*
|
||||
* @return array As defined in initializeResultArray() of AbstractNode
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
if ($this->data['tableName'] !== 'pages' || $this->data['fieldName'] !== 'backend_layout') {
|
||||
throw new \RuntimeException(
|
||||
'The backendLayoutFromParentPage field information can only be used for the backend_layout field of the pages table.',
|
||||
1622109821
|
||||
);
|
||||
}
|
||||
|
||||
$resultArray = $this->initializeResultArray();
|
||||
$parameterArray = $this->data['parameterArray'];
|
||||
|
||||
// In case the backend_layout field of the current page is not empty, no backend layout will be inherited.
|
||||
if (!empty($parameterArray['itemFormElValue'])) {
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
$backendLayoutInformation = '';
|
||||
$languageService = $this->getLanguageService();
|
||||
|
||||
if ($this->data['command'] === 'new') {
|
||||
// In case we deal with a new record, we try to find a possible inherited backend layout in
|
||||
// the rootline. Since there might be further actions, e.g. DataHandler hooks, the actually
|
||||
// resolved backend layout can only be determined, once the record is saved. For now we just
|
||||
// inform about the backend layout, which will most likely be used.
|
||||
foreach ($this->data['rootline'] as $page) {
|
||||
if (!empty($page['backend_layout_next_level']) && ($page['uid'] ?? false)) {
|
||||
$backendLayoutInformation = sprintf(
|
||||
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritFromParentPage'),
|
||||
$this->getFieldValueLabel($parameterArray['fieldConf'], $page['backend_layout_next_level'])
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Get the resolved backend layout for the current page.
|
||||
$backendLayout = $this->backendLayoutView->getBackendLayoutForPage((int)($this->data['databaseRow']['uid'] ?? $this->data['effectivePid'] ?? 0));
|
||||
$backendLayoutInformation = sprintf(
|
||||
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:formEngine.pages.backendLayout.information.inheritedFromParentPage'),
|
||||
$languageService->sL($backendLayout->getTitle())
|
||||
);
|
||||
}
|
||||
|
||||
if ($backendLayoutInformation !== '') {
|
||||
$resultArray['html'] = '<p class="text-variant">' . htmlspecialchars($backendLayoutInformation) . '</p>';
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
protected function getFieldValueLabel(array $fieldConfiguration, string $fieldValue): string
|
||||
{
|
||||
foreach ($fieldConfiguration['config']['items'] as $item) {
|
||||
if (($item['value'] ?? '') === $fieldValue && !empty($item['label'])) {
|
||||
return $item['label'];
|
||||
}
|
||||
}
|
||||
|
||||
$invalidValue = sprintf(
|
||||
$this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue'),
|
||||
$fieldValue
|
||||
);
|
||||
|
||||
return '[ ' . $invalidValue . ' ]';
|
||||
}
|
||||
|
||||
protected function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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\Form\FieldInformation;
|
||||
|
||||
use TYPO3\CMS\Backend\Form\AbstractNode;
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
|
||||
/**
|
||||
* Renders an info badge indicating that no selectable items are available
|
||||
* for a relational field. Shown when backend debug mode is enabled.
|
||||
*/
|
||||
class NoSelectableItemsAvailable extends AbstractNode
|
||||
{
|
||||
public function render(): array
|
||||
{
|
||||
$resultArray = $this->initializeResultArray();
|
||||
$text = htmlspecialchars($this->getLanguageService()->sL(
|
||||
'core.core:labels.noSelectableItemsAvailable'
|
||||
));
|
||||
$resultArray['html'] = '<div class="mb-2"><span class="badge badge-info">' . $text . '</span></div>';
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
private function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user