/** * Helper function to verify various conditions around possible mapping/inheritance configurations * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @param string $renderCondition * @return string */ public function render(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject, $renderCondition) { $content = ''; $extensionPrefix = 'Tx_' . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($domainObject->getExtension()->getExtensionKey()); // an external table should have a loadable TCA configuration and the column definitions // for external tables have to be declared in ext_tables.php $isMappedToExternalTable = FALSE; // table name is only set, if the model is mapped to a table or if the domain object extends a class $tableName = $domainObject->getMapToTable(); if ($tableName && strpos($tableName, strtolower($extensionPrefix) . '_domain_model_') === FALSE) { $isMappedToExternalTable = TRUE; } switch ($renderCondition) { case 'isMappedToInternalTable': if (!$isMappedToExternalTable) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; case 'isMappedToExternalTable': if ($isMappedToExternalTable) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; case 'needsTypeField': if ($this->needsTypeField($domainObject, $isMappedToExternalTable)) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; } return $content; }
/** * 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); } } } } }