예제 #1
0
 /**
  * Helper function to find the parents class recordType
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  * @return string
  */
 public function render(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject)
 {
     $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
     if (isset($classSettings['recordType'])) {
         $parentRecordType = \EBT\ExtensionBuilder\Utility\Tools::convertClassNameToRecordType($classSettings['recordType']);
     } else {
         $parentRecordType = \EBT\ExtensionBuilder\Utility\Tools::convertClassNameToRecordType($domainObject->getParentClass());
         $existingTypes = $GLOBALS['TCA'][$domainObject->getDatabaseTableName()]['types'];
         \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Parent Record type: ' . $parentRecordType, 'extension_builder', 2, $existingTypes);
         if (is_array($existingTypes) && !isset($existingTypes[$parentRecordType])) {
             // no types field for parent record type configured, use the default type 1
             if (isset($existingTypes['1'])) {
                 $parentRecordType = 1;
             } else {
                 //if it not exists get first existing key
                 $parentRecordType = reset(array_keys($existingTypes));
             }
         }
     }
     $this->templateVariableContainer->add('parentModelName', end(explode('\\', $domainObject->getParentClass())));
     $this->templateVariableContainer->add('parentRecordType', $parentRecordType);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove('parentRecordType');
     $this->templateVariableContainer->remove('parentModelName');
     return $content;
 }
 /**
  * @return string
  */
 public function getForeignDatabaseTableName()
 {
     if (is_object($this->foreignModel)) {
         return $this->foreignModel->getDatabaseTableName();
     } else {
         return $this->foreignDatabaseTableName;
     }
 }
예제 #3
0
 /**
  * Returns the current TCA for a domain objects table if the
  * extension is installed
  * TODO: check for previous table name if an extension is renamed
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  *
  * @return array
  */
 protected static function getTcaForDomainObject($domainObject)
 {
     $tableName = $domainObject->getDatabaseTableName();
     GeneralUtility::loadTca($tableName);
     if (isset($GLOBALS['TCA'][$tableName])) {
         return $GLOBALS['TCA'][$tableName];
     } else {
         return NULL;
     }
 }
예제 #4
0
 /**
  * Move custom TCA in files generated by EB versions <= 6.2
  * to the appropriate overrides files
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  */
 public static function moveAdditionalTcaToOverrideFile($domainObject)
 {
     $tcaDir = $domainObject->getExtension()->getExtensionDir() . 'Configuration/TCA/';
     $existingTcaFile = $tcaDir . $domainObject->getName() . '.php';
     if (file_exists($existingTcaFile)) {
         $existingFileContent = file_get_contents($existingTcaFile);
         $fileParts = explode(self::SPLIT_TOKEN, $existingFileContent);
         if (count($fileParts) === 2) {
             $customFileContent = str_replace('$TCA[', '$GLOBALS[\'TCA\'][', $fileParts[1]);
             $customFileContent = '<?php ' . LF . self::SPLIT_TOKEN . LF . str_replace('?>', '', $customFileContent);
             if (!empty($customFileContent)) {
                 $overrideDir = $tcaDir . 'Overrides/';
                 if (!is_dir($overrideDir)) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($tcaDir, 'Overrides');
                 }
                 $success = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($overrideDir . $domainObject->getDatabaseTableName() . '.php', $customFileContent);
                 if (!$success) {
                     throw new \Exception('File ' . $overrideDir . $domainObject->getDatabaseTableName() . '.php could not be created!');
                 } else {
                     unlink($existingTcaFile);
                 }
             }
         }
     }
 }
예제 #5
0
 /**
  * Do we have to create a typefield in database and configuration?
  *
  * A typefield is needed if either the domain objects extends another class
  * or if other domain objects of this extension extend it or if it is mapped
  * to an existing table
  *
  * @param string $tableName
  * @param string $parentClass
  * @param bool $isMappedToExternalTable
  * @return bool
  */
 protected function needsTypeField(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject, $isMappedToExternalTable)
 {
     $needsTypeField = FALSE;
     if ($domainObject->getChildObjects() || $isMappedToExternalTable) {
         $tableName = $domainObject->getDatabaseTableName();
         if (!isset($GLOBALS['TCA'][$tableName]['ctrl']['type']) || $GLOBALS['TCA'][$tableName]['ctrl']['type'] == 'tx_extbase_type') {
             /**
              * if the type field is set but equals the default extbase record type field name it might
              * have been defined by the current extension and thus has to be defined again when rewriting TCA definitions
              * this might result in duplicate definition, but the type field definition is always wrapped in a condition
              * "if (!isset($GLOBALS['TCA'][table][ctrl][type]){ ..."
              *
              * If we don't check the TCA at runtime it would result in a repetition of type field definitions
              * in case an extension has multiple models extending other models of the same extension
              */
             $needsTypeField = TRUE;
         }
     }
     return $needsTypeField;
 }