‪TYPO3CMS  9.5
DefaultDataProvider.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 
24 
29 {
30 
35  protected ‪$tableName = 'backend_layout';
36 
45  public function ‪addBackendLayouts(
46  ‪DataProviderContext $dataProviderContext,
47  ‪BackendLayoutCollection $backendLayoutCollection
48  ) {
49  $layoutData = $this->‪getLayoutData(
50  $dataProviderContext->‪getFieldName(),
51  $dataProviderContext->‪getPageTsConfig(),
52  $dataProviderContext->‪getPageId()
53  );
54 
55  foreach ($layoutData as $data) {
56  $backendLayout = $this->‪createBackendLayout($data);
57  $backendLayoutCollection->‪add($backendLayout);
58  }
59  }
60 
68  public function ‪getBackendLayout($identifier, $pageId)
69  {
70  $backendLayout = null;
71 
72  if ((string)$identifier === 'default') {
73  return $this->‪createDefaultBackendLayout();
74  }
75 
76  $data = ‪BackendUtility::getRecordWSOL($this->tableName, $identifier);
77 
78  if (is_array($data)) {
79  $backendLayout = $this->‪createBackendLayout($data);
80  }
81 
82  return $backendLayout;
83  }
84 
90  protected function ‪createDefaultBackendLayout()
91  {
93  'default',
94  'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.default',
96  );
97  }
98 
105  protected function ‪createBackendLayout(array $data)
106  {
107  $backendLayout = ‪BackendLayout::create($data['uid'], $data['title'], $data['config']);
108  $backendLayout->setIconPath($this->‪getIconPath($data));
109  $backendLayout->setData($data);
110  return $backendLayout;
111  }
112 
119  protected function ‪getIconPath(array $icon)
120  {
121  $fileRepository = GeneralUtility::makeInstance(FileRepository::class);
122  $references = $fileRepository->findByRelation($this->tableName, 'icon', $icon['uid']);
123  if (!empty($references)) {
124  $icon = reset($references);
125  return $icon->getPublicUrl();
126  }
127  return '';
128  }
129 
138  protected function ‪getLayoutData($fieldName, array $pageTsConfig, $pageUid)
139  {
140  $storagePid = $this->‪getStoragePid($pageTsConfig);
141  $pageTsConfigId = $this->‪getPageTSconfigIds($pageTsConfig);
142 
143  // Add layout records
144  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
145  ->getQueryBuilderForTable($this->tableName);
146  $queryBuilder->getRestrictions()
147  ->add(
148  GeneralUtility::makeInstance(
149  WorkspaceRestriction::class,
150  GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id')
151  )
152  );
153  $queryBuilder
154  ->select('*')
155  ->from($this->tableName)
156  ->where(
157  $queryBuilder->expr()->orX(
158  $queryBuilder->expr()->andX(
159  $queryBuilder->expr()->comparison(
160  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
162  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
163  ),
164  $queryBuilder->expr()->comparison(
165  $queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT),
167  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
168  )
169  ),
170  $queryBuilder->expr()->orX(
171  $queryBuilder->expr()->eq(
172  'backend_layout.pid',
173  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT)
174  ),
175  $queryBuilder->expr()->eq(
176  'backend_layout.pid',
177  $queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT)
178  )
179  ),
180  $queryBuilder->expr()->andX(
181  $queryBuilder->expr()->comparison(
182  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
184  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
185  ),
186  $queryBuilder->expr()->eq(
187  'backend_layout.pid',
188  $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)
189  )
190  )
191  )
192  );
193 
194  if (!empty(‪$GLOBALS['TCA'][$this->tableName]['ctrl']['sortby'])) {
195  $queryBuilder->orderBy(‪$GLOBALS['TCA'][$this->tableName]['ctrl']['sortby']);
196  }
197 
198  $statement = $queryBuilder->execute();
199 
200  $results = [];
201  while ($record = $statement->fetch()) {
202  ‪BackendUtility::workspaceOL($this->tableName, $record);
203  if (is_array($record)) {
204  $results[$record['t3ver_oid'] ?: $record['uid']] = $record;
205  }
206  }
207 
208  return $results;
209  }
210 
217  protected function ‪getStoragePid(array $pageTsConfig)
218  {
219  $storagePid = 0;
220 
221  if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
222  $storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
223  }
224 
225  return $storagePid;
226  }
227 
234  protected function ‪getPageTSconfigIds(array $pageTsConfig)
235  {
236  $pageTsConfigIds = [
237  'backend_layout' => 0,
238  'backend_layout_next_level' => 0,
239  ];
240 
241  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
242  $pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
243  }
244 
245  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
246  $pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
247  }
248 
249  return $pageTsConfigIds;
250  }
251 }
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection
Definition: BackendLayoutCollection.php:21
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\$tableName
‪string $tableName
Definition: DefaultDataProvider.php:34
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\EQ
‪const EQ
Definition: ExpressionBuilder.php:34
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface
Definition: DataProviderInterface.php:22
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getLayoutData
‪array getLayoutData($fieldName, array $pageTsConfig, $pageUid)
Definition: DefaultDataProvider.php:137
‪TYPO3
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection\add
‪add(BackendLayout $backendLayout)
Definition: BackendLayoutCollection.php:68
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\createBackendLayout
‪BackendLayout createBackendLayout(array $data)
Definition: DefaultDataProvider.php:104
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\addBackendLayouts
‪addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
Definition: DefaultDataProvider.php:44
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getStoragePid
‪int getStoragePid(array $pageTsConfig)
Definition: DefaultDataProvider.php:216
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getIconPath
‪string getIconPath(array $icon)
Definition: DefaultDataProvider.php:118
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout\create
‪static BackendLayout create($identifier, $title, $configuration)
Definition: BackendLayout.php:52
‪TYPO3\CMS\Core\Resource\FileRepository
Definition: FileRepository.php:32
‪TYPO3\CMS\Backend\View\BackendLayoutView\getDefaultColumnLayout
‪static string getDefaultColumnLayout()
Definition: BackendLayoutView.php:397
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getPageId
‪int getPageId()
Definition: DataProviderContext.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪TYPO3\CMS\Backend\View\BackendLayout
Definition: BackendLayout.php:2
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getBackendLayout
‪BackendLayout null getBackendLayout($identifier, $pageId)
Definition: DefaultDataProvider.php:67
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Utility\BackendUtility\workspaceOL
‪static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
Definition: BackendUtility.php:4048
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getPageTSconfigIds
‪array getPageTSconfigIds(array $pageTsConfig)
Definition: DefaultDataProvider.php:233
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\createDefaultBackendLayout
‪BackendLayout createDefaultBackendLayout()
Definition: DefaultDataProvider.php:89
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:21
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getFieldName
‪string getFieldName()
Definition: DataProviderContext.php:81
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getPageTsConfig
‪array getPageTsConfig()
Definition: DataProviderContext.php:117
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:21
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider
Definition: DefaultDataProvider.php:29
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:37