TYPO3 CMS  TYPO3_7-6
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 
18 
23 {
33  public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
34  {
35  $layoutData = $this->getLayoutData(
36  $dataProviderContext->getFieldName(),
37  $dataProviderContext->getPageTsConfig(),
38  $dataProviderContext->getPageId()
39  );
40 
41  foreach ($layoutData as $data) {
42  $backendLayout = $this->createBackendLayout($data);
43  $backendLayoutCollection->add($backendLayout);
44  }
45  }
46 
54  public function getBackendLayout($identifier, $pageId)
55  {
56  $backendLayout = null;
57 
58  if ((string)$identifier === 'default') {
59  return $this->createDefaultBackendLayout();
60  }
61 
62  $data = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
63  '*',
64  'backend_layout',
65  'uid=' . (int)$identifier . BackendUtility::BEenableFields('backend_layout') . BackendUtility::deleteClause('backend_layout')
66  );
67  if (is_array($data)) {
68  $backendLayout = $this->createBackendLayout($data);
69  }
70 
71  return $backendLayout;
72  }
73 
79  protected function createDefaultBackendLayout()
80  {
81  return BackendLayout::create(
82  'default',
83  'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.backend_layout.default',
85  );
86  }
87 
94  protected function createBackendLayout(array $data)
95  {
96  $backendLayout = BackendLayout::create($data['uid'], $data['title'], $data['config']);
97  $backendLayout->setIconPath($this->getIconPath($data['icon']));
98  $backendLayout->setData($data);
99  return $backendLayout;
100  }
101 
108  protected function getIconPath($icon)
109  {
110  $iconPath = '';
111 
112  if (!empty($icon)) {
113  $path = rtrim($GLOBALS['TCA']['backend_layout']['ctrl']['selicon_field_path'], '/') . '/';
114  $iconPath = '../' . $path . $icon;
115  }
116 
117  return $iconPath;
118  }
119 
128  protected function getLayoutData($fieldName, array $pageTsConfig, $pageUid)
129  {
130  $storagePid = $this->getStoragePid($pageTsConfig);
131  $pageTsConfigId = $this->getPageTSconfigIds($pageTsConfig);
132 
133  // Add layout records
134  $results = $this->getDatabaseConnection()->exec_SELECTgetRows(
135  '*',
136  'backend_layout',
137  '(
138  ( ' . (int)$pageTsConfigId[$fieldName] . ' = 0 AND ' . (int)$storagePid . ' = 0 )
139  OR ( backend_layout.pid = ' . (int)$pageTsConfigId[$fieldName] . ' OR backend_layout.pid = ' . (int)$storagePid . ' )
140  OR ( ' . (int)$pageTsConfigId[$fieldName] . ' = 0 AND backend_layout.pid = ' . (int)$pageUid . ' )
141  ) ' . BackendUtility::BEenableFields('backend_layout') . BackendUtility::deleteClause('backend_layout'),
142  '',
143  'sorting ASC'
144  );
145 
146  if (!is_array($results)) {
147  $results = [];
148  }
149 
150  return $results;
151  }
152 
159  protected function getStoragePid(array $pageTsConfig)
160  {
161  $storagePid = 0;
162 
163  if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
164  $storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
165  }
166 
167  return $storagePid;
168  }
169 
176  protected function getPageTSconfigIds(array $pageTsConfig)
177  {
178  $pageTsConfigIds = [
179  'backend_layout' => 0,
180  'backend_layout_next_level' => 0,
181  ];
182 
183  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
184  $pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
185  }
186 
187  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
188  $pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
189  }
190 
191  return $pageTsConfigIds;
192  }
193 
197  protected function getDatabaseConnection()
198  {
199  return $GLOBALS['TYPO3_DB'];
200  }
201 }
static BEenableFields($table, $inv=false)
getLayoutData($fieldName, array $pageTsConfig, $pageUid)
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']
static deleteClause($table, $tableAlias='')