Example #1
0
 /**
  * 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;
 }
 /**
  * Pre build TCA information for the given model
  *
  * @param string $modelClassName
  *
  * @return array
  */
 public function getTcaInformation($modelClassName)
 {
     $modelInformation = ClassNamingUtility::explodeObjectModelName($modelClassName);
     $extensionName = GeneralUtility::camelCaseToLowerCaseUnderscored($modelInformation['extensionName']);
     $reflectionTableName = ModelUtility::getTableNameByModelReflectionAnnotation($modelClassName);
     $tableName = ModelUtility::getTableNameByModelName($modelClassName);
     $searchFields = [];
     $customFields = $this->getCustomModelFieldTca($modelClassName, $searchFields);
     if ($reflectionTableName !== '') {
         $customConfiguration = ['columns' => $customFields];
         $base = is_array($GLOBALS['TCA'][$reflectionTableName]) ? $GLOBALS['TCA'][$reflectionTableName] : [];
         return ArrayUtility::mergeRecursiveDistinct($base, $customConfiguration);
     }
     $excludes = ModelUtility::getSmartExcludesByModelName($modelClassName);
     $dataSet = $this->getDataSet();
     $dataImplementations = $dataSet->getAllAndExcludeList($excludes);
     $baseTca = $dataSet->getTcaInformation($dataImplementations, $tableName);
     // title
     $fields = array_keys($customFields);
     $labelField = 'title';
     if (!in_array($labelField, $fields)) {
         $labelField = $fields[0];
     }
     try {
         TranslateUtility::assureLabel($tableName, $extensionName);
     } catch (\Exception $ex) {
         // @todo handle
     }
     if (!is_array($baseTca['columns'])) {
         $baseTca['columns'] = [];
     }
     $baseTca['columns'] = ArrayUtility::mergeRecursiveDistinct($baseTca['columns'], $customFields);
     // items
     $showitem = $fields;
     if (!in_array('language', $excludes)) {
         $showitem[] = '--palette--;LLL:EXT:lang/locallang_general.xlf:LGL.language;language';
     }
     if (!in_array('workspaces', $excludes)) {
         $baseTca['ctrl']['shadowColumnsForNewPlaceholders'] .= ',' . $labelField;
     }
     if (GeneralUtility::compat_version('7.0')) {
         $languagePrefix = 'LLL:EXT:frontend/Resources/Private/Language/';
     } else {
         $languagePrefix = 'LLL:EXT:cms/';
     }
     if (!in_array('enableFields', $excludes)) {
         $showitem[] = '--div--;' . $languagePrefix . 'locallang_ttc.xlf:tabs.access';
         $showitem[] = '--palette--;' . $languagePrefix . 'locallang_tca.xlf:pages.palettes.access;access';
     }
     $showitem[] = '--div--;' . $languagePrefix . 'locallang_ttc.xlf:tabs.extended';
     $overrideTca = ['ctrl' => ['title' => TranslateUtility::getLllOrHelpMessage($tableName, $extensionName), 'label' => $labelField, 'tstamp' => 'tstamp', 'crdate' => 'crdate', 'cruser_id' => 'cruser_id', 'dividers2tabs' => true, 'sortby' => 'sorting', 'delete' => 'deleted', 'searchFields' => implode(',', $searchFields), 'iconfile' => IconUtility::getByModelName($modelClassName, GeneralUtility::compat_version('7.0'))], 'interface' => ['showRecordFieldList' => implode(',', array_keys($baseTca['columns']))], 'types' => ['1' => ['showitem' => implode(',', $showitem)]], 'palettes' => ['access' => ['showitem' => 'starttime, endtime, --linebreak--, hidden, editlock, --linebreak--, fe_group']]];
     return ArrayUtility::mergeRecursiveDistinct($baseTca, $overrideTca);
 }