first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,183 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
/**
* Class to represent a backend layout.
*/
class BackendLayout
{
/**
* @var string
*/
protected $identifier;
/**
* @var string
*/
protected $title;
/**
* @var string
*/
protected $description;
/**
* @var string
*/
protected $iconPath;
/**
* @var string
*/
protected $configuration;
/**
* @var array
*/
protected $data;
/**
* @param string $identifier
* @param string $title
* @param string $configuration
* @return BackendLayout
*/
public static function create($identifier, $title, $configuration)
{
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
self::class,
$identifier,
$title,
$configuration
);
}
/**
* @param string $identifier
* @param string $title
* @param string $configuration
*/
public function __construct($identifier, $title, $configuration)
{
$this->setIdentifier($identifier);
$this->setTitle($title);
$this->setConfiguration($configuration);
}
/**
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* @param string $identifier
* @throws \UnexpectedValueException
*/
public function setIdentifier($identifier)
{
if (strpos($identifier, '__') !== false) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597630
);
}
$this->identifier = $identifier;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return string
*/
public function getIconPath()
{
return $this->iconPath;
}
/**
* @param string $iconPath
*/
public function setIconPath($iconPath)
{
$this->iconPath = $iconPath;
}
/**
* @return string
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* @param string $configuration
*/
public function setConfiguration($configuration)
{
$this->configuration = $configuration;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* @param array $data
*/
public function setData(array $data)
{
$this->data = $data;
}
}
@@ -0,0 +1,117 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
/**
* Collection of backend layouts.
*/
class BackendLayoutCollection
{
/**
* @var string
*/
protected $identifier;
/**
* @var array|BackendLayout[]
*/
protected $backendLayouts = [];
/**
* @param string $identifier
*/
public function __construct($identifier)
{
$this->setIdentifier($identifier);
}
/**
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* @param string $identifier
* @throws \UnexpectedValueException
*/
public function setIdentifier($identifier)
{
if (strpos($identifier, '__') !== false) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597631
);
}
$this->identifier = $identifier;
}
/**
* Adds a backend layout to this collection.
*
* @param BackendLayout $backendLayout
* @throws \LogicException
*/
public function add(BackendLayout $backendLayout)
{
$identifier = $backendLayout->getIdentifier();
if (strpos($identifier, '__') !== false) {
throw new \UnexpectedValueException(
'BackendLayout Identifier "' . $identifier . '" must not contain "__"',
1381597628
);
}
if (isset($this->backendLayouts[$identifier])) {
throw new \LogicException(
'Backend Layout ' . $identifier . ' is already defined',
1381559376
);
}
$this->backendLayouts[$identifier] = $backendLayout;
}
/**
* Gets a backend layout by (regular) identifier.
*
* @param string $identifier
* @return BackendLayout|null
*/
public function get($identifier)
{
$backendLayout = null;
if (isset($this->backendLayouts[$identifier])) {
$backendLayout = $this->backendLayouts[$identifier];
}
return $backendLayout;
}
/**
* Gets all backend layouts in this collection.
*
* @return array|BackendLayout[]
*/
public function getAll()
{
return $this->backendLayouts;
}
}
@@ -0,0 +1,129 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
/**
* Collection of backend layout data providers.
*/
class DataProviderCollection implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @var array|DataProviderInterface[]
*/
protected $dataProviders = [];
/**
* @var array
*/
protected $results = [];
/**
* Adds a data provider to this collection.
*
* @param string $identifier
* @param string|object $classNameOrObject
* @throws \UnexpectedValueException
* @throws \LogicException
*/
public function add($identifier, $classNameOrObject)
{
if (strpos($identifier, '__') !== false) {
throw new \UnexpectedValueException(
'Identifier "' . $identifier . '" must not contain "__"',
1381597629
);
}
if (is_object($classNameOrObject)) {
$className = get_class($classNameOrObject);
$dataProvider = $classNameOrObject;
} else {
$className = $classNameOrObject;
$dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($classNameOrObject);
}
if (!$dataProvider instanceof DataProviderInterface) {
throw new \LogicException(
$className . ' must implement interface ' . \TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface::class,
1381269811
);
}
$this->dataProviders[$identifier] = $dataProvider;
}
/**
* Gets all backend layout collections and thus, all
* backend layouts. Each data provider returns its own
* backend layout collection.
*
* @param DataProviderContext $dataProviderContext
* @return array|BackendLayoutCollection[]
*/
public function getBackendLayoutCollections(DataProviderContext $dataProviderContext)
{
$result = [];
foreach ($this->dataProviders as $identifier => $dataProvider) {
$backendLayoutCollection = $this->createBackendLayoutCollection($identifier);
$dataProvider->addBackendLayouts($dataProviderContext, $backendLayoutCollection);
$result[$identifier] = $backendLayoutCollection;
}
return $result;
}
/**
* Gets a backend layout by a combined identifier, which is
* e.g. "myextension_regular" and "myextension" is the identifier
* of the accordant data provider and "regular" the identifier of
* the accordant backend layout.
*
* @param string $combinedIdentifier
* @param int $pageId
* @return BackendLayout|null
*/
public function getBackendLayout($combinedIdentifier, $pageId)
{
$backendLayout = null;
if (strpos($combinedIdentifier, '__') === false) {
$dataProviderIdentifier = 'default';
$backendLayoutIdentifier = $combinedIdentifier;
} else {
list($dataProviderIdentifier, $backendLayoutIdentifier) = explode('__', $combinedIdentifier, 2);
}
if (isset($this->dataProviders[$dataProviderIdentifier])) {
$backendLayout = $this->dataProviders[$dataProviderIdentifier]->getBackendLayout($backendLayoutIdentifier, $pageId);
}
return $backendLayout;
}
/**
* Creates a new backend layout collection.
*
* @param string $identifier
* @return BackendLayoutCollection
*/
protected function createBackendLayoutCollection($identifier)
{
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
BackendLayoutCollection::class,
$identifier
);
}
}
@@ -0,0 +1,136 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
/**
* Context that is forwarded to backend layout data providers.
*/
class DataProviderContext implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @var int
*/
protected $pageId;
/**
* @var string
*/
protected $tableName;
/**
* @var string
*/
protected $fieldName;
/**
* @var array
*/
protected $data;
/**
* @var array
*/
protected $pageTsConfig;
/**
* @return int
*/
public function getPageId()
{
return $this->pageId;
}
/**
* @param int $pageId
* @return DataProviderContext
*/
public function setPageId($pageId)
{
$this->pageId = $pageId;
return $this;
}
/**
* @return string
*/
public function getTableName()
{
return $this->tableName;
}
/**
* @param string $tableName
* @return DataProviderContext
*/
public function setTableName($tableName)
{
$this->tableName = $tableName;
return $this;
}
/**
* @return string
*/
public function getFieldName()
{
return $this->fieldName;
}
/**
* @param string $fieldName
* @return DataProviderContext
*/
public function setFieldName($fieldName)
{
$this->fieldName = $fieldName;
return $this;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* @param array $data
* @return DataProviderContext
*/
public function setData(array $data)
{
$this->data = $data;
return $this;
}
/**
* @return array
*/
public function getPageTsConfig()
{
return $this->pageTsConfig;
}
/**
* @param array $pageTsConfig
* @return DataProviderContext
*/
public function setPageTsConfig(array $pageTsConfig)
{
$this->pageTsConfig = $pageTsConfig;
return $this;
}
}
@@ -0,0 +1,39 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
/**
* Interface for classes which hook into BackendLayoutDataProvider
* to provide additional backend layouts from various sources.
*/
interface DataProviderInterface
{
/**
* Adds backend layouts to the given backend layout collection.
*
* @param DataProviderContext $dataProviderContext
* @param BackendLayoutCollection $backendLayoutCollection
*/
public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection);
/**
* Gets a backend layout by (regular) identifier.
*
* @param string $identifier
* @param int $pageId
* @return BackendLayout|null
*/
public function getBackendLayout($identifier, $pageId);
}
@@ -0,0 +1,251 @@
<?php
namespace TYPO3\CMS\Backend\View\BackendLayout;
/*
* 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!
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Backend layout data provider class
*/
class DefaultDataProvider implements DataProviderInterface
{
/**
* @var string
* Table name for backend_layouts
*/
protected $tableName = 'backend_layout';
/**
* Adds backend layouts to the given backend layout collection.
* The default backend layout ('default_default') is not added
* since it's the default fallback if nothing is specified.
*
* @param DataProviderContext $dataProviderContext
* @param BackendLayoutCollection $backendLayoutCollection
*/
public function addBackendLayouts(
DataProviderContext $dataProviderContext,
BackendLayoutCollection $backendLayoutCollection
) {
$layoutData = $this->getLayoutData(
$dataProviderContext->getFieldName(),
$dataProviderContext->getPageTsConfig(),
$dataProviderContext->getPageId()
);
foreach ($layoutData as $data) {
$backendLayout = $this->createBackendLayout($data);
$backendLayoutCollection->add($backendLayout);
}
}
/**
* Gets a backend layout by (regular) identifier.
*
* @param string $identifier
* @param int $pageId
* @return BackendLayout|null
*/
public function getBackendLayout($identifier, $pageId)
{
$backendLayout = null;
if ((string)$identifier === 'default') {
return $this->createDefaultBackendLayout();
}
$data = BackendUtility::getRecordWSOL($this->tableName, $identifier);
if (is_array($data)) {
$backendLayout = $this->createBackendLayout($data);
}
return $backendLayout;
}
/**
* Creates a backend layout with the default configuration.
*
* @return BackendLayout
*/
protected function createDefaultBackendLayout()
{
return BackendLayout::create(
'default',
'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.default',
\TYPO3\CMS\Backend\View\BackendLayoutView::getDefaultColumnLayout()
);
}
/**
* Creates a new backend layout using the given record data.
*
* @param array $data
* @return BackendLayout
*/
protected function createBackendLayout(array $data)
{
$backendLayout = BackendLayout::create($data['uid'], $data['title'], $data['config']);
$backendLayout->setIconPath($this->getIconPath($data));
$backendLayout->setData($data);
return $backendLayout;
}
/**
* Resolves the icon from the database record
*
* @param array $icon
* @return string
*/
protected function getIconPath(array $icon)
{
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$references = $fileRepository->findByRelation($this->tableName, 'icon', $icon['uid']);
if (!empty($references)) {
$icon = reset($references);
return $icon->getPublicUrl();
}
return '';
}
/**
* Get all layouts from the core's default data provider.
*
* @param string $fieldName the name of the field the layouts are provided for (either backend_layout or backend_layout_next_level)
* @param array $pageTsConfig PageTSconfig of the given page
* @param int $pageUid the ID of the page wea re getting the layouts for
* @return array $layouts A collection of layout data of the registered provider
*/
protected function getLayoutData($fieldName, array $pageTsConfig, $pageUid)
{
$storagePid = $this->getStoragePid($pageTsConfig);
$pageTsConfigId = $this->getPageTSconfigIds($pageTsConfig);
// Add layout records
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($this->tableName);
$queryBuilder->getRestrictions()
->add(
GeneralUtility::makeInstance(
WorkspaceRestriction::class,
GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id')
)
);
$queryBuilder
->select('*')
->from($this->tableName)
->where(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->comparison(
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
),
$queryBuilder->expr()->comparison(
$queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->eq(
'backend_layout.pid',
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'backend_layout.pid',
$queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->andX(
$queryBuilder->expr()->comparison(
$queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'backend_layout.pid',
$queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)
)
)
)
);
if (!empty($GLOBALS['TCA'][$this->tableName]['ctrl']['sortby'])) {
$queryBuilder->orderBy($GLOBALS['TCA'][$this->tableName]['ctrl']['sortby']);
}
$statement = $queryBuilder->execute();
$results = [];
while ($record = $statement->fetch()) {
BackendUtility::workspaceOL($this->tableName, $record);
if (is_array($record)) {
$results[$record['t3ver_oid'] ?: $record['uid']] = $record;
}
}
return $results;
}
/**
* Returns the storage PID from TCEFORM.
*
* @param array $pageTsConfig
* @return int
*/
protected function getStoragePid(array $pageTsConfig)
{
$storagePid = 0;
if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
$storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
}
return $storagePid;
}
/**
* Returns the page TSconfig from TCEFORM.
*
* @param array $pageTsConfig
* @return array
*/
protected function getPageTSconfigIds(array $pageTsConfig)
{
$pageTsConfigIds = [
'backend_layout' => 0,
'backend_layout_next_level' => 0,
];
if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
$pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
}
if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
$pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
}
return $pageTsConfigIds;
}
}