‪TYPO3CMS  9.5
DataProviderCollection.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected ‪$dataProviders = [];
26 
30  protected ‪$results = [];
31 
40  public function ‪add($identifier, $classNameOrObject)
41  {
42  if (strpos($identifier, '__') !== false) {
43  throw new \UnexpectedValueException(
44  'Identifier "' . $identifier . '" must not contain "__"',
45  1381597629
46  );
47  }
48 
49  if (is_object($classNameOrObject)) {
50  $className = get_class($classNameOrObject);
51  $dataProvider = $classNameOrObject;
52  } else {
53  $className = $classNameOrObject;
54  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($classNameOrObject);
55  }
56 
57  if (!$dataProvider instanceof ‪DataProviderInterface) {
58  throw new \LogicException(
59  $className . ' must implement interface ' . \‪TYPO3\CMS\Backend\View\‪BackendLayout\DataProviderInterface::class,
60  1381269811
61  );
62  }
63 
64  $this->dataProviders[$identifier] = $dataProvider;
65  }
66 
75  public function ‪getBackendLayoutCollections(‪DataProviderContext $dataProviderContext)
76  {
77  $result = [];
78 
79  foreach ($this->dataProviders as $identifier => $dataProvider) {
80  $backendLayoutCollection = $this->‪createBackendLayoutCollection($identifier);
81  $dataProvider->addBackendLayouts($dataProviderContext, $backendLayoutCollection);
82  $result[$identifier] = $backendLayoutCollection;
83  }
84 
85  return $result;
86  }
87 
98  public function ‪getBackendLayout($combinedIdentifier, $pageId)
99  {
100  $backendLayout = null;
101 
102  if (strpos($combinedIdentifier, '__') === false) {
103  $dataProviderIdentifier = 'default';
104  $backendLayoutIdentifier = $combinedIdentifier;
105  } else {
106  list($dataProviderIdentifier, $backendLayoutIdentifier) = explode('__', $combinedIdentifier, 2);
107  }
108 
109  if (isset($this->dataProviders[$dataProviderIdentifier])) {
110  $backendLayout = $this->dataProviders[$dataProviderIdentifier]->getBackendLayout($backendLayoutIdentifier, $pageId);
111  }
112 
113  return $backendLayout;
114  }
115 
122  protected function ‪createBackendLayoutCollection($identifier)
123  {
124  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
125  BackendLayoutCollection::class,
126  $identifier
127  );
128  }
129 }
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:21
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface
Definition: DataProviderInterface.php:22
‪TYPO3
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection
Definition: DataProviderCollection.php:21
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\add
‪add($identifier, $classNameOrObject)
Definition: DataProviderCollection.php:38
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\$results
‪array $results
Definition: DataProviderCollection.php:28
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\getBackendLayoutCollections
‪array BackendLayoutCollection[] getBackendLayoutCollections(DataProviderContext $dataProviderContext)
Definition: DataProviderCollection.php:73
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\createBackendLayoutCollection
‪BackendLayoutCollection createBackendLayoutCollection($identifier)
Definition: DataProviderCollection.php:120
‪TYPO3\CMS\Backend\View\BackendLayout
Definition: BackendLayout.php:2
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\$dataProviders
‪array DataProviderInterface[] $dataProviders
Definition: DataProviderCollection.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:21
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderCollection\getBackendLayout
‪BackendLayout null getBackendLayout($combinedIdentifier, $pageId)
Definition: DataProviderCollection.php:96
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:21