Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject1
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject2
  * @param array $classHierarchy
  * @return bool
  */
 protected function isParentOf($domainObject1, $domainObject2, $classHierarchy)
 {
     if ($domainObject2->getParentClass() === $domainObject1->getFullQualifiedClassName()) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
Exemplo n.º 3
0
 /**
  *
  * create a new class object based on the template and the related domain object
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  *
  * @return void
  */
 protected function createNewModelClassObject($domainObject)
 {
     $this->classFileObject = clone $this->templateFileObject;
     $this->classObject = clone $this->templateFileObject->getFirstClass();
     $this->classObject->resetAll();
     // start with plain class
     $this->classObject->setName($domainObject->getName());
     if ($domainObject->isEntity()) {
         $parentClass = $domainObject->getParentClass();
         if (empty($parentClass)) {
             $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey());
         }
     } else {
         $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey());
     }
     $this->classObject->setParentClassName($parentClass);
     $this->classObject->setDescription($domainObject->getDescription());
 }
Exemplo n.º 4
0
 /**
  * cover all cases:
  * 1. extend TYPO3 class like fe_users (no mapping table needed)
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
  */
 private function validateMapping(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject)
 {
     $parentClass = $domainObject->getParentClass();
     $tableName = $domainObject->getMapToTable();
     $extensionPrefix = 'Tx_' . GeneralUtility::underscoredToUpperCamelCase($domainObject->getExtension()->getExtensionKey()) . '_Domain_Model_';
     if (!empty($parentClass)) {
         $classConfiguration = $this->configurationManager->getExtbaseClassConfiguration($parentClass);
         GeneralUtility::devlog('class settings ' . $parentClass, 'extension_builder', 0, $classConfiguration);
         if (!isset($classConfiguration['tableName'])) {
             if (!$tableName) {
                 $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': ' . LF . 'The mapping table could not be detected from Extbase Configuration. Please enter a table name', self::ERROR_MAPPING_NO_TABLE);
             }
         } else {
             // get the table name from the parent class configuration
             $tableName = $classConfiguration['tableName'];
         }
         if (!class_exists($parentClass, TRUE)) {
             $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': the parent class ' . LF . $parentClass . 'seems not to exist ', self::ERROR_MAPPING_NO_PARENTCLASS);
         }
     }
     if ($tableName) {
         if (in_array($tableName, array('tt_content', 'pages')) || preg_match("/^(pages_|be_|sys_|static_|cf_)/", $tableName)) {
             $this->validationResult['warnings'][] = new ExtensionException('The configuration for table "' . $tableName . '" is not compatible' . LF . ' with extbase. You have to configure it yourself if you want to map' . LF . ' to this table', self::ERROR_MAPPING_TO_INCOMPATIBLE_TABLE);
         }
         if (strpos($extensionPrefix, $tableName) !== FALSE) {
             // the domainObject extends a class of the same extension
             if (!$parentClass) {
                 $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': you have to define' . LF . 'a parent class if you map to a table of another domain object of the same extension ', self::ERROR_MAPPING_NO_PARENTCLASS);
             }
         }
         if (!isset($GLOBALS['TCA'][$tableName])) {
             $this->validationResult['errors'][] = new ExtensionException('There is no entry for table "' . $tableName . '" of ' . $domainObject->getName() . ' in TCA. ' . LF . 'For technical reasons you can only extend tables with TCA configuration.', self::ERROR_MAPPING_NO_TCA);
         }
     }
     if (isset($GLOBALS['TCA'][$tableName]['ctrl']['type'])) {
         $dataTypeRes = $this->getDatabaseConnection()->sql_query('DESCRIBE ' . $tableName);
         while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($dataTypeRes)) {
             if ($row['Field'] == $GLOBALS['TCA'][$tableName]['ctrl']['type']) {
                 if (strpos($row['Type'], 'int') !== FALSE) {
                     $this->validationResult['warnings'][] = new ExtensionException('The configured type field for table "' . $tableName . '" is of type ' . $row['Type'] . '' . LF . 'This means the type field can not be used for defining the record type. ' . LF . 'You have to configure the mappings yourself if you want to map to this' . LF . 'table or extend the correlated class', self::ERROR_MAPPING_WRONG_TYPEFIELD_CONFIGURATION);
                 }
             }
         }
     }
 }