2 namespace TYPO3\CMS\Core\Category;
63 $this->
template = str_repeat(PHP_EOL, 3) .
'CREATE TABLE %s (' . PHP_EOL
64 .
' %s int(11) DEFAULT \'0\' NOT NULL' . PHP_EOL .
');' . str_repeat(PHP_EOL, 3);
85 public function add($extensionKey, $tableName, $fieldName =
'categories', array $options = array(), $override =
false)
88 if (empty($tableName) || !is_string($tableName)) {
89 throw new \InvalidArgumentException(
'No or invalid table name "' . $tableName .
'" given.', 1369122038);
91 if (empty($extensionKey) || !is_string($extensionKey)) {
92 throw new \InvalidArgumentException(
'No or invalid extension key "' . $extensionKey .
'" given.', 1397836158);
96 $this->
remove($tableName, $fieldName);
100 $this->registry[$tableName][$fieldName] = $options;
101 $this->extensions[$extensionKey][$tableName][$fieldName] = $fieldName;
103 if (!isset(
$GLOBALS[
'TCA'][$tableName][
'columns']) && isset(
$GLOBALS[
'TCA'][$tableName][
'ctrl'][
'dynamicConfigFile'])) {
108 if (isset(
$GLOBALS[
'TCA'][$tableName][
'columns'])) {
124 return array_keys($this->extensions);
134 return array_keys($this->registry);
148 $menuType = isset($configuration[
'row'][
'menu_type'][0]) ? $configuration[
'row'][
'menu_type'][0] :
'';
150 if ($menuType ===
'categorized_pages') {
152 }
elseif ($menuType ===
'categorized_content') {
153 $table =
'tt_content';
157 throw new \UnexpectedValueException(
'The given menu_type is not supported.', 1381823570);
160 foreach ($this->registry as $tableName => $fields) {
161 if ($tableName === $table) {
162 foreach ($fields as $fieldName => $options) {
164 $configuration[
'items'][] = array($fieldLabel, $fieldName);
179 return isset($this->registry[$tableName][$fieldName]);
204 if (!isset($this->extensions[$extensionKey]) || !is_array($this->extensions[$extensionKey])) {
209 foreach ($this->extensions[$extensionKey] as $tableName => $fields) {
210 foreach ($fields as $fieldName) {
211 $sql .= sprintf($this->
template, $tableName, $fieldName);
226 foreach ($this->registry as $tableName => $fields) {
227 foreach ($fields as $fieldName => $_) {
241 $this->
addTcaColumn($tableName, $fieldName, $this->registry[$tableName][$fieldName]);
242 $this->
addToAllTCAtypes($tableName, $fieldName, $this->registry[$tableName][$fieldName]);
254 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'defaultCategorizedTables'],
257 foreach ($defaultCategorizedTables as $defaultCategorizedTable) {
259 $this->
add(
'core', $defaultCategorizedTable,
'categories');
279 if (isset(
$GLOBALS[
'TCA'][$tableName][
'columns'])) {
280 if (empty($options[
'fieldList'])) {
283 $fieldList = $options[
'fieldList'];
287 if (!empty($options[
'typesList'])) {
288 $typesList = $options[
'typesList'];
292 if (!empty($options[
'position'])) {
293 $position = $options[
'position'];
312 if (!isset($this->addedCategoryTabs[$tableName])) {
313 $fieldList .=
'--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, ';
314 $this->addedCategoryTabs[$tableName] = $tableName;
316 $fieldList .= $fieldName;
333 protected function addTcaColumn($tableName, $fieldName, array $options)
336 if (isset(
$GLOBALS[
'TCA'][$tableName][
'columns'])) {
338 $label =
'LLL:EXT:lang/locallang_tca.xlf:sys_category.categories';
339 if (!empty($options[
'label'])) {
340 $label = $options[
'label'];
345 if (isset($options[
'exclude'])) {
346 $exclude = (bool)$options[
'exclude'];
349 $fieldConfiguration = empty($options[
'fieldConfiguration']) ? array() : $options[
'fieldConfiguration'];
353 'exclude' => $exclude,
355 'config' => static::getTcaFieldConfiguration($tableName, $fieldName, $fieldConfiguration),
359 if (isset($options[
'l10n_mode'])) {
360 $columns[$fieldName][
'l10n_mode'] = $options[
'l10n_mode'];
362 if (isset($options[
'l10n_display'])) {
363 $columns[$fieldName][
'l10n_display'] = $options[
'l10n_display'];
367 if (empty(
$GLOBALS[
'TCA'][
'sys_category'][
'columns'][
'items'][
'config'][
'MM_oppositeUsage'][$tableName])) {
368 $GLOBALS[
'TCA'][
'sys_category'][
'columns'][
'items'][
'config'][
'MM_oppositeUsage'][$tableName] = array();
370 if (!in_array($fieldName,
$GLOBALS[
'TCA'][
'sys_category'][
'columns'][
'items'][
'config'][
'MM_oppositeUsage'][$tableName])) {
371 $GLOBALS[
'TCA'][
'sys_category'][
'columns'][
'items'][
'config'][
'MM_oppositeUsage'][$tableName][] = $fieldName;
376 (!isset($options[
'interface']) || $options[
'interface'])
377 && !empty(
$GLOBALS[
'TCA'][$tableName][
'interface'][
'showRecordFieldList'])
380 $GLOBALS[
'TCA'][$tableName][
'interface'][
'showRecordFieldList'] .=
',' . $fieldName;
399 public static function getTcaFieldConfiguration($tableName, $fieldName =
'categories', array $fieldConfigurationOverride = array())
402 $fieldConfiguration = array(
404 'renderType' =>
'selectTree',
405 'foreign_table' =>
'sys_category',
406 'foreign_table_where' =>
' AND sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.sorting ASC',
407 'MM' =>
'sys_category_record_mm',
408 'MM_opposite_field' =>
'items',
409 'MM_match_fields' => array(
410 'tablenames' => $tableName,
411 'fieldname' => $fieldName,
416 'treeConfig' => array(
417 'parentField' =>
'parent',
418 'appearance' => array(
420 'showHeader' =>
true,
427 if (!empty($fieldConfigurationOverride)) {
430 $fieldConfigurationOverride
434 return $fieldConfiguration;
448 return array(
'sqlString' => $sqlString);
462 return array(
'sqlString' => $sqlString,
'extensionKey' => $extensionKey);
479 protected function remove($tableName, $fieldName)
485 unset($this->registry[$tableName][$fieldName]);
487 foreach ($this->extensions as $extensionKey => $tableFieldConfig) {
488 foreach ($tableFieldConfig as $extTableName => $fieldNameArray) {
489 if ($extTableName === $tableName && isset($fieldNameArray[$fieldName])) {
490 unset($this->extensions[$extensionKey][$tableName][$fieldName]);
497 if (empty($this->registry[$tableName]) && isset($this->addedCategoryTabs[$tableName])) {
498 unset($this->addedCategoryTabs[$tableName]);