TYPO3 CMS  TYPO3_7-6
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, $identifier
126  );
127  }
128 }
getBackendLayoutCollections(DataProviderContext $dataProviderContext)