TYPO3 CMS  TYPO3_7-6
TreeDataProviderFactory.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 
22 {
33  public static function getDataProvider(array $tcaConfiguration, $table, $field, $currentValue)
34  {
36  $dataProvider = null;
37  if (!isset($tcaConfiguration['treeConfig']) | !is_array($tcaConfiguration['treeConfig'])) {
38  throw new \InvalidArgumentException('TCA Tree configuration is invalid: "treeConfig" array is missing', 1288215890);
39  }
40 
41  if (!empty($tcaConfiguration['treeConfig']['dataProvider'])) {
42  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($tcaConfiguration['treeConfig']['dataProvider'], $tcaConfiguration, $table, $field, $currentValue);
43  }
44  if (!isset($tcaConfiguration['internal_type'])) {
45  $tcaConfiguration['internal_type'] = 'db';
46  }
47  if ($tcaConfiguration['internal_type'] === 'db') {
48  $unselectableUids = [];
49  if ($dataProvider === null) {
50  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider::class);
51  }
52  if (isset($tcaConfiguration['foreign_table'])) {
53  $tableName = $tcaConfiguration['foreign_table'];
54  $dataProvider->setTableName($tableName);
55  if ($tableName == $table) {
56  $unselectableUids[] = $currentValue['uid'];
57  }
58  } else {
59  throw new \InvalidArgumentException('TCA Tree configuration is invalid: "foreign_table" not set', 1288215888);
60  }
61  if (isset($tcaConfiguration['foreign_label'])) {
62  $dataProvider->setLabelField($tcaConfiguration['foreign_label']);
63  } else {
64  $dataProvider->setLabelField($GLOBALS['TCA'][$tableName]['ctrl']['label']);
65  }
66  $dataProvider->setTreeId(md5($table . '|' . $field));
67  $dataProvider->setSelectedList($currentValue);
68 
69  $treeConfiguration = $tcaConfiguration['treeConfig'];
70  if (isset($treeConfiguration['rootUid'])) {
71  $dataProvider->setRootUid((int)$treeConfiguration['rootUid']);
72  }
73  if (isset($treeConfiguration['appearance']['expandAll'])) {
74  $dataProvider->setExpandAll((bool)$treeConfiguration['appearance']['expandAll']);
75  }
76  if (isset($treeConfiguration['appearance']['maxLevels'])) {
77  $dataProvider->setLevelMaximum((int)$treeConfiguration['appearance']['maxLevels']);
78  }
79  if (isset($treeConfiguration['appearance']['nonSelectableLevels'])) {
80  $dataProvider->setNonSelectableLevelList($treeConfiguration['appearance']['nonSelectableLevels']);
81  } elseif (isset($treeConfiguration['rootUid'])) {
82  $dataProvider->setNonSelectableLevelList('');
83  }
84  if (isset($treeConfiguration['childrenField'])) {
85  $dataProvider->setLookupMode(DatabaseTreeDataProvider::MODE_CHILDREN);
86  $dataProvider->setLookupField($treeConfiguration['childrenField']);
87  } elseif (isset($treeConfiguration['parentField'])) {
88  $dataProvider->setLookupMode(DatabaseTreeDataProvider::MODE_PARENT);
89  $dataProvider->setLookupField($treeConfiguration['parentField']);
90  } else {
91  throw new \InvalidArgumentException('TCA Tree configuration is invalid: neither "childrenField" nor "parentField" is set', 1288215889);
92  }
93  $dataProvider->setItemUnselectableList($unselectableUids);
94  } elseif ($tcaConfiguration['internal_type'] === 'file' && $dataProvider === null) {
95  // @todo Not implemented yet
96  throw new \InvalidArgumentException('TCA Tree configuration is invalid: tree for "internal_type=file" not implemented yet', 1288215891);
97  } elseif ($dataProvider === null) {
98  throw new \InvalidArgumentException('TCA Tree configuration is invalid: tree for "internal_type=' . $tcaConfiguration['internal_type'] . '" not implemented yet', 1288215892);
99  }
100  return $dataProvider;
101  }
102 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']