TYPO3 CMS  TYPO3_6-2
FileCollectionRegistry.php
Go to the documentation of this file.
1 <?php
3 
21 
27  protected $types = array();
28 
32  public function __construct() {
33  foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] as $type => $class) {
34  $this->registerFileCollectionClass($class, $type);
35  }
36  }
37 
47  public function registerFileCollectionClass($className, $type, $override = FALSE) {
48 
49  if (strlen($type) > 30) {
50  throw new \InvalidArgumentException('FileCollection type can have a max string length of 30 bytes', 1391295611);
51  }
52 
53  if (!class_exists($className)) {
54  throw new \InvalidArgumentException('Class ' . $className . ' does not exist.', 1391295613);
55  }
56 
57  if (!in_array('TYPO3\\CMS\\Core\\Resource\\Collection\\AbstractFileCollection', class_parents($className), TRUE)) {
58  throw new \InvalidArgumentException('FileCollection ' . $className . ' needs to extend the AbstractFileCollection.', 1391295633);
59  }
60 
61  if (isset($this->types[$type])) {
62  // Return immediately without changing configuration
63  if ($this->types[$type] === $className) {
64  return TRUE;
65  } elseif (!$override) {
66  throw new \InvalidArgumentException('FileCollections ' . $type . ' is already registered.', 1391295643);
67  }
68  }
69 
70  $this->types[$type] = $className;
71  return TRUE;
72  }
73 
83  public function addTypeToTCA($type, $label, $availableFields, array $additionalColumns = array()) {
84 
85  $GLOBALS['TCA']['sys_file_collection']['types'][$type] = array(
86  'showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, title;;1, type, ' . $availableFields
87  );
88 
89  // search for existing type when found override label
90  $typeFound = FALSE;
91  foreach ($GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'] as $key => $item) {
92  if ($item[1] === $type) {
93  $typeFound = TRUE;
94  $GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$key][0] = $label;
95  }
96  }
97  if (!$typeFound) {
98  $GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][] = array(
99  0 => $label,
100  1 => $type
101  );
102  }
103  if ($additionalColumns !== array()) {
104  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['sys_file_collection']['columns'], $additionalColumns);
105  }
106  return $GLOBALS['TCA']['sys_file_collection'];
107  }
108 
116  public function getFileCollectionClass($type) {
117  if (!isset($this->types[$type])) {
118  throw new \InvalidArgumentException('Desired FileCollection type "' . $type . '" is not in the list of available FileCollections.', 1391295644);
119  }
120  return $this->types[$type];
121  }
122 
129  public function fileCollectionTypeExists($type) {
130  return isset($this->types[$type]);
131  }
132 
133 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
addTypeToTCA($type, $label, $availableFields, array $additionalColumns=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]