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