TYPO3 CMS  TYPO3_6-2
TreeDataProviderFactory.php
Go to the documentation of this file.
1 <?php
3 
23 
34  static public function getDataProvider(array $tcaConfiguration, $table, $field, $currentValue) {
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 = array();
49  if ($dataProvider === NULL) {
50  $dataProvider = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Tree\\TableConfiguration\\DatabaseTreeDataProvider');
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(\TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider::MODE_CHILDREN);
86  $dataProvider->setLookupField($treeConfiguration['childrenField']);
87  } elseif (isset($treeConfiguration['parentField'])) {
88  $dataProvider->setLookupMode(\TYPO3\CMS\Core\Tree\TableConfiguration\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 
95  } elseif ($tcaConfiguration['internal_type'] === 'file' && $dataProvider === NULL) {
96  // TODO Not implemented yet
97  throw new \InvalidArgumentException('TCA Tree configuration is invalid: tree for "internal_type=file" not implemented yet', 1288215891);
98  } elseif ($dataProvider === NULL) {
99  throw new \InvalidArgumentException('TCA Tree configuration is invalid: tree for "internal_type=' . $tcaConfiguration['internal_type'] . '" not implemented yet', 1288215892);
100  }
101  return $dataProvider;
102  }
103 
104 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]