‪TYPO3CMS  ‪main
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 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 
32 {
37  protected ‪$tableName = 'backend_layout';
38 
44  public function ‪addBackendLayouts(
45  ‪DataProviderContext $dataProviderContext,
46  ‪BackendLayoutCollection $backendLayoutCollection
47  ) {
48  $layoutData = $this->‪getLayoutData(
49  $dataProviderContext->‪getFieldName(),
50  $dataProviderContext->‪getPageTsConfig(),
51  $dataProviderContext->‪getPageId()
52  );
53 
54  foreach ($layoutData as ‪$data) {
55  $backendLayout = $this->‪createBackendLayout($data);
56  $backendLayoutCollection->‪add($backendLayout);
57  }
58  }
59 
67  public function ‪getBackendLayout(‪$identifier, $pageId)
68  {
69  $backendLayout = null;
70 
71  if ((string)‪$identifier === 'default') {
72  return $this->‪createDefaultBackendLayout();
73  }
74 
75  ‪$data = BackendUtility::getRecordWSOL($this->tableName, (int)‪$identifier);
76 
77  if (is_array(‪$data)) {
78  $backendLayout = $this->‪createBackendLayout(‪$data);
79  }
80 
81  return $backendLayout;
82  }
83 
89  protected function ‪createDefaultBackendLayout()
90  {
92  'default',
93  'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.default',
95  );
96  }
97 
103  protected function ‪createBackendLayout(array ‪$data)
104  {
105  $backendLayout = ‪BackendLayout::create(‪$data['uid'], ‪$data['title'], ‪$data['config']);
106  $backendLayout->setIconPath($this->‪getIconPath($data));
107  $backendLayout->setData(‪$data);
108  return $backendLayout;
109  }
110 
116  protected function ‪getIconPath(array $icon)
117  {
118  $fileRepository = GeneralUtility::makeInstance(FileRepository::class);
119  $references = $fileRepository->findByRelation($this->tableName, 'icon', (int)$icon['uid']);
120  if (!empty($references)) {
121  $icon = reset($references);
122  return $icon->getPublicUrl();
123  }
124  return '';
125  }
126 
135  protected function ‪getLayoutData($fieldName, array $pageTsConfig, $pageUid)
136  {
137  $storagePid = $this->‪getStoragePid($pageTsConfig);
138  $pageTsConfigId = $this->‪getPageTSconfigIds($pageTsConfig);
139 
140  // Add layout records
141  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
142  ->getQueryBuilderForTable($this->tableName);
143  $queryBuilder->getRestrictions()
144  ->add(
145  GeneralUtility::makeInstance(
146  WorkspaceRestriction::class,
147  GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id')
148  )
149  );
150  $queryBuilder
151  ->select('*')
152  ->from($this->tableName)
153  ->where(
154  $queryBuilder->expr()->or(
155  $queryBuilder->expr()->and(
156  $queryBuilder->expr()->comparison(
157  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], ‪Connection::PARAM_INT),
159  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
160  ),
161  $queryBuilder->expr()->comparison(
162  $queryBuilder->createNamedParameter($storagePid, ‪Connection::PARAM_INT),
164  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
165  )
166  ),
167  $queryBuilder->expr()->or(
168  $queryBuilder->expr()->eq(
169  'backend_layout.pid',
170  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], ‪Connection::PARAM_INT)
171  ),
172  $queryBuilder->expr()->eq(
173  'backend_layout.pid',
174  $queryBuilder->createNamedParameter($storagePid, ‪Connection::PARAM_INT)
175  )
176  ),
177  $queryBuilder->expr()->and(
178  $queryBuilder->expr()->comparison(
179  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], ‪Connection::PARAM_INT),
181  $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)
182  ),
183  $queryBuilder->expr()->eq(
184  'backend_layout.pid',
185  $queryBuilder->createNamedParameter($pageUid, ‪Connection::PARAM_INT)
186  )
187  )
188  )
189  );
190 
191  if (!empty(‪$GLOBALS['TCA'][$this->tableName]['ctrl']['sortby'])) {
192  $queryBuilder->orderBy(‪$GLOBALS['TCA'][$this->tableName]['ctrl']['sortby']);
193  }
194 
195  $statement = $queryBuilder->executeQuery();
196 
197  $results = [];
198  while (‪$record = $statement->fetchAssociative()) {
199  BackendUtility::workspaceOL($this->tableName, ‪$record);
200  if (is_array(‪$record)) {
201  $results[‪$record['t3ver_oid'] ?: ‪$record['uid']] = ‪$record;
202  }
203  }
204 
205  return $results;
206  }
207 
213  protected function ‪getStoragePid(array $pageTsConfig)
214  {
215  $storagePid = 0;
216 
217  if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
218  $storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
219  }
220 
221  return $storagePid;
222  }
223 
229  protected function ‪getPageTSconfigIds(array $pageTsConfig)
230  {
231  $pageTsConfigIds = [
232  'backend_layout' => 0,
233  'backend_layout_next_level' => 0,
234  ];
235 
236  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
237  $pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
238  }
239 
240  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
241  $pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
242  }
243 
244  return $pageTsConfigIds;
245  }
246 }
‪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\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:50
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:40
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getPageTsConfig
‪getPageTsConfig()
Definition: DataProviderContext.php:116
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\EQ
‪const EQ
Definition: ExpressionBuilder.php:41
‪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:134
‪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:102
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\addBackendLayouts
‪addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
Definition: DefaultDataProvider.php:43
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getStoragePid
‪int getStoragePid(array $pageTsConfig)
Definition: DefaultDataProvider.php:212
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getIconPath
‪string getIconPath(array $icon)
Definition: DefaultDataProvider.php:115
‪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:38
‪TYPO3\CMS\Backend\View\BackendLayoutView\getDefaultColumnLayout
‪static string getDefaultColumnLayout()
Definition: BackendLayoutView.php:380
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getPageId
‪int getPageId()
Definition: DataProviderContext.php:48
‪TYPO3\CMS\Backend\View\BackendLayout
Definition: BackendLayout.php:16
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:39
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getBackendLayout
‪BackendLayout null getBackendLayout($identifier, $pageId)
Definition: DefaultDataProvider.php:66
‪TYPO3\CMS\Backend\View\BackendLayoutView
Definition: BackendLayoutView.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\getPageTSconfigIds
‪array getPageTSconfigIds(array $pageTsConfig)
Definition: DefaultDataProvider.php:228
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider\createDefaultBackendLayout
‪BackendLayout createDefaultBackendLayout()
Definition: DefaultDataProvider.php:88
‪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:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext\getFieldName
‪string getFieldName()
Definition: DataProviderContext.php:84
‪TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext
Definition: DataProviderContext.php:24
‪TYPO3\CMS\Backend\View\BackendLayout\DefaultDataProvider
Definition: DefaultDataProvider.php:32
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39