TYPO3 CMS  TYPO3_6-2
BackendLayoutView.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\View;
3 
20 
27 
32 
36  protected $selectedCombinedIdentifier = array();
37 
41  protected $selectedBackendLayout = array();
42 
46  public function __construct() {
47  $this->initializeDataProviderCollection();
48  }
49 
55  protected function initializeDataProviderCollection() {
58  'TYPO3\\CMS\\Backend\\View\\BackendLayout\\DataProviderCollection'
59  );
60 
62  'default',
63  'TYPO3\\CMS\\Backend\\View\\BackendLayout\\DefaultDataProvider'
64  );
65 
66  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['BackendLayoutDataProvider'])) {
67  $dataProviders = (array) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['BackendLayoutDataProvider'];
68  foreach ($dataProviders as $identifier => $className) {
69  $dataProviderCollection->add($identifier, $className);
70  }
71  }
72 
74  }
75 
79  public function setDataProviderCollection(BackendLayout\DataProviderCollection $dataProviderCollection) {
80  $this->dataProviderCollection = $dataProviderCollection;
81  }
82 
86  public function getDataProviderCollection() {
88  }
89 
97  public function addBackendLayoutItems(array $parameters) {
98  $pageId = $this->determinePageId($parameters['table'], $parameters['row']);
99  $pageTsConfig = (array) BackendUtility::getPagesTSconfig($pageId);
100  $identifiersToBeExcluded = $this->getIdentifiersToBeExcluded($pageTsConfig);
101 
102  $dataProviderContext = $this->createDataProviderContext()
103  ->setPageId($pageId)
104  ->setData($parameters['row'])
105  ->setTableName($parameters['table'])
106  ->setFieldName($parameters['field'])
107  ->setPageTsConfig($pageTsConfig);
108 
109  $backendLayoutCollections = $this->getDataProviderCollection()->getBackendLayoutCollections($dataProviderContext);
110  foreach ($backendLayoutCollections as $backendLayoutCollection) {
111  $combinedIdentifierPrefix = '';
112  if ($backendLayoutCollection->getIdentifier() !== 'default') {
113  $combinedIdentifierPrefix = $backendLayoutCollection->getIdentifier() . '__';
114  }
115 
116  foreach ($backendLayoutCollection->getAll() as $backendLayout) {
117  $combinedIdentifier = $combinedIdentifierPrefix . $backendLayout->getIdentifier();
118 
119  if (in_array($combinedIdentifier, $identifiersToBeExcluded, TRUE)) {
120  continue;
121  }
122 
123  $parameters['items'][] = array(
124  $this->getLanguageService()->sL($backendLayout->getTitle()),
125  $combinedIdentifier,
126  $backendLayout->getIconPath(),
127  );
128  }
129  }
130  }
131 
139  protected function determinePageId($tableName, array $data) {
140  $pageId = NULL;
141 
142  if (strpos($data['uid'], 'NEW') === 0) {
143  // negative uid_pid values of content elements indicate that the element has been inserted after an existing element
144  // so there is no pid to get the backendLayout for and we have to get that first
145  if ($data['pid'] < 0) {
146  $existingElement = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
147  'pid', $tableName, 'uid=' . abs($data['pid'])
148  );
149  if ($existingElement !== NULL) {
150  $pageId = $existingElement['pid'];
151  }
152  } else {
153  $pageId = $data['pid'];
154  }
155  } elseif ($tableName === 'pages') {
156  $pageId = $data['uid'];
157  } else {
158  $pageId = $data['pid'];
159  }
160 
161  return $pageId;
162  }
163 
170  public function getSelectedCombinedIdentifier($pageId) {
171  if (!isset($this->selectedCombinedIdentifier[$pageId])) {
172  $page = $this->getPage($pageId);
173  $this->selectedCombinedIdentifier[$pageId] = (string) $page['backend_layout'];
174 
175  if ($this->selectedCombinedIdentifier[$pageId] === '-1') {
176  // If it is set to "none" - don't use any
177  $this->selectedCombinedIdentifier[$pageId] = FALSE;
178  } elseif ($this->selectedCombinedIdentifier[$pageId] === '' || $this->selectedCombinedIdentifier[$pageId] === '0') {
179  // If it not set check the root-line for a layout on next level and use this
180  // (root-line starts with current page and has page "0" at the end)
181  $rootLine = $this->getRootLine($pageId);
182  // Remove first and last element (current and root page)
183  array_shift($rootLine);
184  array_pop($rootLine);
185  foreach ($rootLine as $rootLinePage) {
186  $this->selectedCombinedIdentifier[$pageId] = (string) $rootLinePage['backend_layout_next_level'];
187  if ($this->selectedCombinedIdentifier[$pageId] === '-1') {
188  // If layout for "next level" is set to "none" - don't use any and stop searching
189  $this->selectedCombinedIdentifier[$pageId] = FALSE;
190  break;
191  } elseif ($this->selectedCombinedIdentifier[$pageId] !== '' && $this->selectedCombinedIdentifier[$pageId] !== '0') {
192  // Stop searching if a layout for "next level" is set
193  break;
194  }
195  }
196  }
197  }
198  // If it is set to a positive value use this
199  return $this->selectedCombinedIdentifier[$pageId];
200  }
201 
208  protected function getIdentifiersToBeExcluded(array $pageTSconfig) {
209  $identifiersToBeExcluded = array();
210 
211  if (ArrayUtility::isValidPath($pageTSconfig, 'options./backendLayout./exclude')) {
212  $identifiersToBeExcluded = GeneralUtility::trimExplode(
213  ',',
214  ArrayUtility::getValueByPath($pageTSconfig, 'options./backendLayout./exclude'),
215  TRUE
216  );
217  }
218 
219  return $identifiersToBeExcluded;
220  }
221 
230  public function colPosListItemProcFunc(array $parameters) {
231  $pageId = $this->determinePageId($parameters['table'], $parameters['row']);
232 
233  if ($pageId !== NULL) {
234  $parameters['items'] = $this->addColPosListLayoutItems($pageId, $parameters['items']);
235  }
236  }
237 
245  protected function addColPosListLayoutItems($pageId, $items) {
246  $layout = $this->getSelectedBackendLayout($pageId);
247  if ($layout && $layout['__items']) {
248  $items = $layout['__items'];
249  }
250  return $items;
251  }
252 
259  public function getColPosListItemsParsed($id) {
260  $tsConfig = BackendUtility::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
261  $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
263  $tceForms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
264  $tcaItems = $tcaConfig['items'];
265  $tcaItems = $tceForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
266  if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
267  $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
268  }
269  foreach (GeneralUtility::trimExplode(',', $tsConfig['properties']['removeItems'], TRUE) as $removeId) {
270  foreach ($tcaItems as $key => $item) {
271  if ($item[1] == $removeId) {
272  unset($tcaItems[$key]);
273  }
274  }
275  }
276  return $tcaItems;
277  }
278 
285  public function getSelectedBackendLayout($pageId) {
286  if (isset($this->selectedBackendLayout[$pageId])) {
287  return $this->selectedBackendLayout[$pageId];
288  }
289  $backendLayoutData = NULL;
290 
292  // If no backend layout is selected, use default
293  if (empty($selectedCombinedIdentifier)) {
294  $selectedCombinedIdentifier = 'default';
295  }
296 
297  $backendLayout = $this->getDataProviderCollection()->getBackendLayout($selectedCombinedIdentifier, $pageId);
298  // If backend layout is not found available anymore, use default
299  if (is_null($backendLayout)) {
300  $selectedCombinedIdentifier = 'default';
301  $backendLayout = $this->getDataProviderCollection()->getBackendLayout($selectedCombinedIdentifier, $pageId);
302  }
303 
304  if (!empty($backendLayout)) {
306  $parser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
308  $conditionMatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
309  $parser->parse($parser->checkIncludeLines($backendLayout->getConfiguration()), $conditionMatcher);
310 
311  $backendLayoutData = array();
312  $backendLayoutData['config'] = $backendLayout->getConfiguration();
313  $backendLayoutData['__config'] = $parser->setup;
314  $backendLayoutData['__items'] = array();
315  $backendLayoutData['__colPosList'] = array();
316 
317  // create items and colPosList
318  if (!empty($backendLayoutData['__config']['backend_layout.']['rows.'])) {
319  foreach ($backendLayoutData['__config']['backend_layout.']['rows.'] as $row) {
320  if (!empty($row['columns.'])) {
321  foreach ($row['columns.'] as $column) {
322  $backendLayoutData['__items'][] = array(
323  GeneralUtility::isFirstPartOfStr($column['name'], 'LLL:') ? $this->getLanguageService()->sL($column['name']) : $column['name'],
324  $column['colPos'],
325  NULL
326  );
327  $backendLayoutData['__colPosList'][] = $column['colPos'];
328  }
329  }
330  }
331  }
332 
333  $this->selectedBackendLayout[$pageId] = $backendLayoutData;
334  }
335 
336  return $backendLayoutData;
337  }
338 
345  static public function getDefaultColumnLayout() {
346  return '
347  backend_layout {
348  colCount = 4
349  rowCount = 1
350  rows {
351  1 {
352  columns {
353  1 {
354  name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.0
355  colPos = 1
356  }
357  2 {
358  name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.1
359  colPos = 0
360  }
361  3 {
362  name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.2
363  colPos = 2
364  }
365  4 {
366  name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.3
367  colPos = 3
368  }
369  }
370  }
371  }
372  }
373  ';
374  }
375 
382  protected function getPage($pageId) {
383  $page = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
384  'uid, pid, backend_layout',
385  'pages',
386  'uid=' . (int)$pageId
387  );
388  BackendUtility::workspaceOL('pages', $page);
389  return $page;
390  }
391 
398  protected function getRootLine($pageId) {
399  return BackendUtility::BEgetRootLine($pageId, '', TRUE);
400  }
401 
405  protected function createDataProviderContext() {
407  'TYPO3\\CMS\\Backend\\View\\BackendLayout\\DataProviderContext'
408  );
409  }
410 
414  protected function getDatabaseConnection() {
415  return $GLOBALS['TYPO3_DB'];
416  }
417 
421  protected function getLanguageService() {
422  return $GLOBALS['LANG'];
423  }
424 
425 }
$parameters
Definition: FileDumpEID.php:15
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static getValueByPath(array $array, $path, $delimiter='/')
static isFirstPartOfStr($str, $partStr)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
setDataProviderCollection(BackendLayout\DataProviderCollection $dataProviderCollection)
static isValidPath(array $array, $path, $delimiter='/')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getPagesTSconfig($id, $rootLine=NULL, $returnPartArray=FALSE)