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