TYPO3 CMS  TYPO3_6-2
DefaultDataProvider.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
36  public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection) {
37  $layoutData = $this->getLayoutData(
38  $dataProviderContext->getFieldName(),
39  $dataProviderContext->getPageTsConfig(),
40  $dataProviderContext->getPageId()
41  );
42 
43  foreach ($layoutData as $data) {
44  $backendLayout = $this->createBackendLayout($data);
45  $backendLayoutCollection->add($backendLayout);
46  }
47  }
48 
56  public function getBackendLayout($identifier, $pageId) {
57  $backendLayout = NULL;
58 
59  if ((string) $identifier === 'default') {
60  return $this->createDefaultBackendLayout();
61  }
62 
63  $data = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
64  '*',
65  'backend_layout',
66  'uid=' . (int)$identifier . BackendUtility::BEenableFields('backend_layout') . BackendUtility::deleteClause('backend_layout')
67  );
68  if (is_array($data)) {
69  $backendLayout = $this->createBackendLayout($data);
70  }
71 
72  return $backendLayout;
73  }
74 
80  protected function createDefaultBackendLayout() {
81  return BackendLayout::create(
82  'default',
83  'LLL:EXT:cms/locallang_tca.xlf:pages.backend_layout.default',
85  );
86  }
87 
94  protected function createBackendLayout(array $data) {
95  $backendLayout = BackendLayout::create($data['uid'], $data['title'], $data['config']);
96  $backendLayout->setIconPath($this->getIconPath($data['icon']));
97  $backendLayout->setData($data);
98  return $backendLayout;
99  }
100 
107  protected function getIconPath($icon) {
108  $iconPath = '';
109 
110  if (!empty($icon)) {
111  $path = rtrim($GLOBALS['TCA']['backend_layout']['ctrl']['selicon_field_path'], '/') . '/';
112  $iconPath = '../' . $path . $icon;
113  }
114 
115  return $iconPath;
116  }
117 
126  protected function getLayoutData($fieldName, array $pageTsConfig, $pageUid) {
127  $storagePid = $this->getStoragePid($pageTsConfig);
128  $pageTsConfigId = $this->getPageTSconfigIds($pageTsConfig);
129 
130  // Add layout records
131  $results = $this->getDatabaseConnection()->exec_SELECTgetRows(
132  '*',
133  'backend_layout',
134  '(
135  ( ' . (int)$pageTsConfigId[$fieldName] . ' = 0 AND ' . (int)$storagePid . ' = 0 )
136  OR ( backend_layout.pid = ' . (int)$pageTsConfigId[$fieldName] . ' OR backend_layout.pid = ' . (int)$storagePid . ' )
137  OR ( ' . (int)$pageTsConfigId[$fieldName] . ' = 0 AND backend_layout.pid = ' . (int)$pageUid . ' )
138  ) ' . BackendUtility::BEenableFields('backend_layout') . BackendUtility::deleteClause('backend_layout'),
139  '',
140  'sorting ASC'
141  );
142 
143  if (!is_array($results)) {
144  $results = array();
145  }
146 
147  return $results;
148  }
149 
156  protected function getStoragePid(array $pageTsConfig) {
157  $storagePid = 0;
158 
159  if (!empty($pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'])) {
160  $storagePid = (int)$pageTsConfig['TCEFORM.']['pages.']['_STORAGE_PID'];
161  }
162 
163  return $storagePid;
164  }
165 
172  protected function getPageTSconfigIds(array $pageTsConfig) {
173  $pageTsConfigIds = array(
174  'backend_layout' => 0,
175  'backend_layout_next_level' => 0,
176  );
177 
178  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'])) {
179  $pageTsConfigIds['backend_layout'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout.']['PAGE_TSCONFIG_ID'];
180  }
181 
182  if (!empty($pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'])) {
183  $pageTsConfigIds['backend_layout_next_level'] = (int)$pageTsConfig['TCEFORM.']['pages.']['backend_layout_next_level.']['PAGE_TSCONFIG_ID'];
184  }
185 
186  return $pageTsConfigIds;
187  }
188 
192  protected function getDatabaseConnection() {
193  return $GLOBALS['TYPO3_DB'];
194  }
195 
196 }
getLayoutData($fieldName, array $pageTsConfig, $pageUid)
addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
static create($identifier, $title, $configuration)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')