‪TYPO3CMS  ‪main
DataProviderCollection.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
27 {
31  protected array ‪$dataProviders = [];
32  protected array ‪$results = [];
33 
37  public function ‪add(string ‪$identifier, string|object $classNameOrObject): void
38  {
39  if (str_contains(‪$identifier, '__')) {
40  throw new \UnexpectedValueException(
41  'Identifier "' . ‪$identifier . '" must not contain "__"',
42  1381597629
43  );
44  }
45 
46  if (is_object($classNameOrObject)) {
47  $className = get_class($classNameOrObject);
48  $dataProvider = $classNameOrObject;
49  } else {
50  $className = $classNameOrObject;
51  $dataProvider = GeneralUtility::makeInstance($classNameOrObject);
52  }
53 
54  if (!$dataProvider instanceof ‪DataProviderInterface) {
55  throw new \LogicException(
56  $className . ' must implement interface ' . DataProviderInterface::class,
57  1381269811
58  );
59  }
60 
61  $this->dataProviders[‪$identifier] = $dataProvider;
62  }
63 
71  public function ‪getBackendLayoutCollections(‪DataProviderContext $dataProviderContext): array
72  {
73  $result = [];
74 
75  foreach ($this->dataProviders as ‪$identifier => $dataProvider) {
76  $backendLayoutCollection = $this->‪createBackendLayoutCollection(‪$identifier);
77  $dataProvider->addBackendLayouts($dataProviderContext, $backendLayoutCollection);
78  $result[‪$identifier] = $backendLayoutCollection;
79  }
80 
81  return $result;
82  }
83 
90  public function ‪getBackendLayout(string $combinedIdentifier, int $pageId): ?‪BackendLayout
91  {
92  $backendLayout = null;
93 
94  if (!str_contains($combinedIdentifier, '__')) {
95  $dataProviderIdentifier = 'default';
96  $backendLayoutIdentifier = $combinedIdentifier;
97  } else {
98  [$dataProviderIdentifier, $backendLayoutIdentifier] = explode('__', $combinedIdentifier, 2);
99  }
100 
101  if (isset($this->dataProviders[$dataProviderIdentifier])) {
102  $backendLayout = $this->dataProviders[$dataProviderIdentifier]->getBackendLayout($backendLayoutIdentifier, $pageId);
103  }
104 
105  return $backendLayout;
106  }
107 
112  {
113  return GeneralUtility::makeInstance(
114  BackendLayoutCollection::class,
116  );
117  }
118 }
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\getBackendLayoutCollections
‪BackendLayoutCollection[] getBackendLayoutCollections(DataProviderContext $dataProviderContext)
Definition: DataProviderCollection.php:71
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\getBackendLayout
‪getBackendLayout(string $combinedIdentifier, int $pageId)
Definition: DataProviderCollection.php:90
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface
Definition: DataProviderInterface.php:23
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection
Definition: DataProviderCollection.php:27
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\createBackendLayoutCollection
‪createBackendLayoutCollection(string $identifier)
Definition: DataProviderCollection.php:111
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\add
‪add(string $identifier, string|object $classNameOrObject)
Definition: DataProviderCollection.php:37
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\$results
‪array $results
Definition: DataProviderCollection.php:32
‪TYPO3\CMS\Backend\View\BackendLayout
Definition: BackendLayout.php:18
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\$dataProviders
‪array $dataProviders
Definition: DataProviderCollection.php:31
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\$identifier
‪string $identifier
Definition: BackendLayout.php:28
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:26