TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
26 
31  protected $tableName = 'backend_layout';
32 
41  public function addBackendLayouts(
42  DataProviderContext $dataProviderContext,
43  BackendLayoutCollection $backendLayoutCollection
44  ) {
45  $layoutData = $this->getLayoutData(
46  $dataProviderContext->getFieldName(),
47  $dataProviderContext->getPageTsConfig(),
48  $dataProviderContext->getPageId()
49  );
50 
51  foreach ($layoutData as $data) {
52  $backendLayout = $this->createBackendLayout($data);
53  $backendLayoutCollection->add($backendLayout);
54  }
55  }
56 
64  public function getBackendLayout($identifier, $pageId)
65  {
66  $backendLayout = null;
67 
68  if ((string)$identifier === 'default') {
69  return $this->createDefaultBackendLayout();
70  }
71 
72  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
73  ->getQueryBuilderForTable($this->tableName);
74  $data = $queryBuilder
75  ->select('*')
76  ->from($this->tableName)
77  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identifier, \PDO::PARAM_INT)))
78  ->execute()
79  ->fetch();
80 
81  if (is_array($data)) {
82  $backendLayout = $this->createBackendLayout($data);
83  }
84 
85  return $backendLayout;
86  }
87 
93  protected function createDefaultBackendLayout()
94  {
95  return BackendLayout::create(
96  'default',
97  'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.default',
99  );
100  }
101 
108  protected function createBackendLayout(array $data)
109  {
110  $backendLayout = BackendLayout::create($data['uid'], $data['title'], $data['config']);
111  $backendLayout->setIconPath($this->getIconPath($data['icon']));
112  $backendLayout->setData($data);
113  return $backendLayout;
114  }
115 
122  protected function getIconPath($icon)
123  {
124  $iconPath = '';
125 
126  if (!empty($icon)) {
127  $path = rtrim($GLOBALS['TCA']['backend_layout']['ctrl']['selicon_field_path'], '/') . '/';
128  $iconPath = $path . $icon;
129  }
130 
131  return $iconPath;
132  }
133 
142  protected function getLayoutData($fieldName, array $pageTsConfig, $pageUid)
143  {
144  $storagePid = $this->getStoragePid($pageTsConfig);
145  $pageTsConfigId = $this->getPageTSconfigIds($pageTsConfig);
146 
147  // Add layout records
148  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
149  ->getQueryBuilderForTable($this->tableName);
150  $queryBuilder
151  ->select('*')
152  ->from($this->tableName)
153  ->where(
154  $queryBuilder->expr()->orX(
155  $queryBuilder->expr()->andX(
156  $queryBuilder->expr()->comparison(
157  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
158  Comparison::EQ,
159  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
160  ),
161  $queryBuilder->expr()->comparison(
162  $queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT),
163  Comparison::EQ,
164  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
165  )
166  ),
167  $queryBuilder->expr()->orX(
168  $queryBuilder->expr()->eq(
169  'backend_layout.pid',
170  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT)
171  ),
172  $queryBuilder->expr()->eq(
173  'backend_layout.pid',
174  $queryBuilder->createNamedParameter($storagePid, \PDO::PARAM_INT)
175  )
176  ),
177  $queryBuilder->expr()->andX(
178  $queryBuilder->expr()->comparison(
179  $queryBuilder->createNamedParameter($pageTsConfigId[$fieldName], \PDO::PARAM_INT),
180  Comparison::EQ,
181  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
182  ),
183  $queryBuilder->expr()->eq(
184  'backend_layout.pid',
185  $queryBuilder->createNamedParameter($pageUid, \PDO::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  $results = $queryBuilder
196  ->execute()
197  ->fetchAll();
198 
199  return $results;
200  }
201 
208  protected function getStoragePid(array $pageTsConfig)
209  {
210  $storagePid = 0;
211 
212  if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
213  $storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
214  }
215 
216  return $storagePid;
217  }
218 
225  protected function getPageTSconfigIds(array $pageTsConfig)
226  {
227  $pageTsConfigIds = [
228  'backend_layout' => 0,
229  'backend_layout_next_level' => 0,
230  ];
231 
232  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
233  $pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
234  }
235 
236  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
237  $pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
238  }
239 
240  return $pageTsConfigIds;
241  }
242 }
getLayoutData($fieldName, array $pageTsConfig, $pageUid)
static makeInstance($className,... $constructorArguments)
addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
static create($identifier, $title, $configuration)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']