/** * Check and create the TCA information * disable this for better performance */ public static function checkAndCreateTcaInformation() { $register = SmartObjectRegister::getRegister(); $baseTemplatePath = ExtensionManagementUtility::extPath('autoloader', 'Resources/Private/Templates/TcaFiles/'); $defaultTemplate = GeneralUtility::getUrl($baseTemplatePath . 'Default.tmpl'); $overrideTemplate = GeneralUtility::getUrl($baseTemplatePath . 'Override.tmpl'); $search = ['__modelName__', '__tableName__', '__extensionKey__']; foreach ($register as $model) { $extensionKey = ClassNamingUtility::getExtensionKeyByModel($model); $basePath = ExtensionManagementUtility::extPath($extensionKey) . 'Configuration/TCA/'; $tableName = ModelUtility::getTableNameByModelReflectionAnnotation($model); if ($tableName !== '') { $tcaFileName = $basePath . 'Overrides/' . $tableName . '.php'; $template = $overrideTemplate; } else { $tableName = ModelUtility::getTableNameByModelName($model); $tcaFileName = $basePath . $tableName . '.php'; $template = $defaultTemplate; } if (!is_file($tcaFileName)) { $replace = [str_replace('\\', '\\\\', $model), $tableName, $extensionKey]; $content = str_replace($search, $replace, $template); FileUtility::writeFileAndCreateFolder($tcaFileName, $content); } } }
/** * Find table and model information for the given extension key * * @param string $extensionKey * * @return array */ protected function findTableAndModelInformationForExtension($extensionKey) { $information = []; $register = SmartObjectRegister::getRegister(); foreach ($register as $class) { $parts = ClassNamingUtility::explodeObjectModelName($class); if (GeneralUtility::camelCaseToLowerCaseUnderscored($parts['extensionName']) === $extensionKey) { if (ModelUtility::getTableNameByModelReflectionAnnotation($class) === '') { $information[] = ['table' => ModelUtility::getTableNameByModelName($class), 'class' => $class]; } } } return $information; }
/** * Find table and model information for the given extension key * * @param string $extensionKey * * @return array */ protected function findTableAndModelInformationForExtension($extensionKey) { $information = []; $register = SmartObjectRegister::getRegister(); foreach ($register as $class) { $parts = ClassNamingUtility::explodeObjectModelName($class); if (GeneralUtility::camelCaseToLowerCaseUnderscored($parts['extensionName']) === $extensionKey) { if (ModelUtility::getTableNameByModelReflectionAnnotation($class) === '') { $modelInformation = SmartObjectInformationService::getInstance()->getCustomModelFieldTca($class); $information[] = ['table' => ModelUtility::getTableNameByModelName($class), 'properties' => array_keys($modelInformation)]; } } } return $information; }
/** * Add the given classes to the SmartObject Register * * @param array $loaderInformation */ protected function addClassesToSmartRegister($loaderInformation) { foreach ($loaderInformation as $configuration) { SmartObjectRegister::register($configuration); } }
/** * Run the loading process for the ext_tables.php file * * @param Loader $loader * @param array $loaderInformation * * @return NULL */ public function loadExtensionTables(Loader $loader, array $loaderInformation) { if (!$loaderInformation) { return null; } $createWizardHeader = []; $predefinedWizards = ['common', 'special', 'forms', 'plugins']; // Add the divider $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'][] = [TranslateUtility::getLllString('tt_content.' . $loader->getExtensionKey() . '.header', $loader->getExtensionKey()), '--div--']; foreach ($loaderInformation as $e => $config) { SmartObjectRegister::register($config['modelClass']); $typeKey = $loader->getExtensionKey() . '_' . $e; ExtensionManagementUtility::addPlugin([TranslateUtility::getLllOrHelpMessage('content.element.' . $e, $loader->getExtensionKey()), $typeKey, $config['iconExt']], 'CType'); if (!isset($GLOBALS['TCA']['tt_content']['types'][$typeKey]['showitem'])) { $baseTcaConfiguration = $this->wrapDefaultTcaConfiguration($config['fieldConfiguration'], (bool) $config['noHeader']); if (ExtensionManagementUtility::isLoaded('gridelements')) { $baseTcaConfiguration .= ',tx_gridelements_container,tx_gridelements_columns'; } $GLOBALS['TCA']['tt_content']['types'][$typeKey]['showitem'] = $baseTcaConfiguration; } // RTE if (isset($config['richTextFields']) && is_array($config['richTextFields']) && $config['richTextFields']) { foreach ($config['richTextFields'] as $field) { $GLOBALS['TCA']['tt_content']['types'][$typeKey]['columnsOverrides'][$field] = ['config' => ['type' => 'text'], 'defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css]']; } } IconUtility::addTcaTypeIcon('tt_content', $typeKey, $config['icon']); $tabName = $config['tabInformation'] ? $config['tabInformation'] : $loader->getExtensionKey(); if (!in_array($tabName, $predefinedWizards) && !in_array($tabName, $createWizardHeader)) { $createWizardHeader[] = $tabName; } ExtensionManagementUtility::addPageTSConfig(' mod.wizards.newContentElement.wizardItems.' . $tabName . '.elements.' . $typeKey . ' { icon = ' . $config['icon'] . ' title = ' . TranslateUtility::getLllOrHelpMessage('wizard.' . $e, $loader->getExtensionKey()) . ' description = ' . TranslateUtility::getLllOrHelpMessage('wizard.' . $e . '.description', $loader->getExtensionKey()) . ' tt_content_defValues { CType = ' . $typeKey . ' } } mod.wizards.newContentElement.wizardItems.' . $tabName . '.show := addToList(' . $typeKey . ')'); $cObjectConfiguration = ['extensionKey' => $loader->getExtensionKey(), 'backendTemplatePath' => 'EXT:' . $loader->getExtensionKey() . '/Resources/Private/Templates/Content/' . $config['model'] . 'Backend.html', 'modelClass' => $config['modelClass']]; $GLOBALS['TYPO3_CONF_VARS']['AUTOLOADER']['ContentObject'][$loader->getExtensionKey() . '_' . GeneralUtility::camelCaseToLowerCaseUnderscored($config['model'])] = $cObjectConfiguration; } if ($createWizardHeader) { foreach ($createWizardHeader as $element) { ExtensionManagementUtility::addPageTSConfig(' mod.wizards.newContentElement.wizardItems.' . $element . ' { show = * header = ' . TranslateUtility::getLllOrHelpMessage('wizard.' . $element . '.header', $loader->getExtensionKey()) . ' }'); } } return null; }
/** * Get the smart objects for the given extension * * @param $extensionKey * * @return mixed */ private function getSmartObjectsForExtensionKey($extensionKey) { $smartObjects = SmartObjectRegister::getRegister(); $extensionObjects = []; foreach ($smartObjects as $className) { $objectExtension = ClassNamingUtility::getExtensionKeyByModel($className); if ($objectExtension === $extensionKey) { $extensionObjects[] = $className; } } return $extensionObjects; }
/** * Get the default TCA incl. smart object fields. * Add missing fields to the existing TCA structure. * * @param string $extensionKey * @param string $tableName * * @return array */ public static function getTcaOverrideInformation($extensionKey, $tableName) { $return = isset($GLOBALS['TCA'][$tableName]) ? $GLOBALS['TCA'][$tableName] : []; $classNames = SmartObjectRegister::getRegister(); $informationService = SmartObjectInformationService::getInstance(); foreach ($classNames as $className) { if (ClassNamingUtility::getExtensionKeyByModel($className) !== $extensionKey) { continue; } if (self::getTableNameByModelReflectionAnnotation($className) === $tableName) { $additionalTca = $informationService->getCustomModelFieldTca($className); foreach ($additionalTca as $fieldName => $configuration) { if (!isset($return['columns'][$fieldName])) { $return['columns'][$fieldName] = $configuration; } } } } return $return; }