/** * 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; }
/** * * @param array $relationJsonConfiguration * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @throws \Exception * @return \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation */ public function buildRelation($relationJsonConfiguration, $domainObject) { $relationSchemaClassName = 'EBT\\ExtensionBuilder\\Domain\\Model\\DomainObject\\Relation\\'; $relationSchemaClassName .= ucfirst($relationJsonConfiguration['relationType']) . 'Relation'; if (!class_exists($relationSchemaClassName)) { throw new \Exception('Relation of type ' . $relationSchemaClassName . ' not found (configured in "' . $relationJsonConfiguration['relationName'] . '")'); } /** * @var $relation \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation */ $relation = new $relationSchemaClassName(); $relation->setName($relationJsonConfiguration['relationName']); $relation->setLazyLoading((bool) $relationJsonConfiguration['lazyLoading']); $relation->setExcludeField($relationJsonConfiguration['propertyIsExcludeField']); $relation->setDescription($relationJsonConfiguration['relationDescription']); $relation->setUniqueIdentifier($relationJsonConfiguration['uid']); $relation->setType($relationJsonConfiguration['type']); if (!empty($relationJsonConfiguration['foreignRelationClass'])) { // relations without wires if (strpos($relationJsonConfiguration['foreignRelationClass'], '\\') > 0) { // add trailing slash if not set $relationJsonConfiguration['foreignRelationClass'] = '\\' . $relationJsonConfiguration['foreignRelationClass']; } $relation->setForeignClassName($relationJsonConfiguration['foreignRelationClass']); $relation->setRelatedToExternalModel(true); $extbaseClassConfiguration = $this->configurationManager->getExtbaseClassConfiguration($relationJsonConfiguration['foreignRelationClass']); if (isset($extbaseClassConfiguration['tableName'])) { $foreignDatabaseTableName = $extbaseClassConfiguration['tableName']; $this->relatedForeignTables[$foreignDatabaseTableName] = 1; } else { $foreignDatabaseTableName = Tools::parseTableNameFromClassName($relationJsonConfiguration['foreignRelationClass']); } $relation->setForeignDatabaseTableName($foreignDatabaseTableName); if ($relation instanceof \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\ZeroToManyRelation) { $foreignKeyName = strtolower($domainObject->getName()); if (\EBT\ExtensionBuilder\Service\ValidationService::isReservedMYSQLWord($foreignKeyName)) { $foreignKeyName = 'tx_' . $foreignKeyName; } if (isset($this->relatedForeignTables[$foreignDatabaseTableName])) { $foreignKeyName .= $this->relatedForeignTables[$foreignDatabaseTableName]; $this->relatedForeignTables[$foreignDatabaseTableName] += 1; } else { $foreignDatabaseTableName = Tools::parseTableNameFromClassName($relationJsonConfiguration['foreignRelationClass']); } $relation->setForeignDatabaseTableName($foreignDatabaseTableName); } if ($relation->isFileReference() && !empty($relationJsonConfiguration['maxItems'])) { /** @var $relation \EBT\ExtensionBuilder\Domain\Model\DomainObject\FileProperty */ $relation->setMaxItems($relationJsonConfiguration['maxItems']); if (!empty($relationJsonConfiguration['allowedFileTypes'])) { $relation->setAllowedFileTypes($relationJsonConfiguration['allowedFileTypes']); } } } return $relation; }
/** * @test */ public function getExtbaseClassConfigurationReturnsCorrectValue() { $classConfiguration = $this->configurationManager->getExtbaseClassConfiguration('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser'); self::assertSame($classConfiguration['tableName'], 'fe_users'); }
/** * * @param array $extensionBuildConfiguration * @return \EBT\ExtensionBuilder\Domain\Model\Extension $extension */ public function build(array $extensionBuildConfiguration) { /** @var $extension \EBT\ExtensionBuilder\Domain\Model\Extension */ $extension = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Domain\\Model\\Extension'); $globalProperties = $extensionBuildConfiguration['properties']; if (!is_array($globalProperties)) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Error: Extension properties not submitted! ' . $extension->getOriginalExtensionKey(), 'builder', 3, $globalProperties); throw new \Exception('Extension properties not submitted!'); } $this->setExtensionProperties($extension, $globalProperties); if (is_array($globalProperties['persons'])) { foreach ($globalProperties['persons'] as $personValues) { $person = $this->buildPerson($personValues); $extension->addPerson($person); } } if (is_array($globalProperties['plugins'])) { foreach ($globalProperties['plugins'] as $pluginValues) { $plugin = $this->buildPlugin($pluginValues); $extension->addPlugin($plugin); } } if (is_array($globalProperties['backendModules'])) { foreach ($globalProperties['backendModules'] as $backendModuleValues) { $backendModule = $this->buildBackendModule($backendModuleValues); $extension->addBackendModule($backendModule); } } // classes if (is_array($extensionBuildConfiguration['modules'])) { foreach ($extensionBuildConfiguration['modules'] as $singleModule) { $domainObject = $this->objectSchemaBuilder->build($singleModule['value']); if ($domainObject->isSubClass() && !$domainObject->isMappedToExistingTable()) { // we try to get the table from Extbase configuration $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass()); if (isset($classSettings['tableName'])) { $tableName = $classSettings['tableName']; } else { // we use the default table name $tableName = \EBT\ExtensionBuilder\Utility\Tools::parseTableNameFromClassName($domainObject->getParentClass()); } if (!isset($GLOBALS['TCA'][$tableName])) { throw new \Exception('Table definitions for table ' . $tableName . ' could not be loaded. You can only map to tables with existing TCA or extend classes of installed extensions!'); } $domainObject->setMapToTable($tableName); } $extension->addDomainObject($domainObject); } // add child objects - needed to generate correct TCA for inheritance foreach ($extension->getDomainObjects() as $domainObject1) { foreach ($extension->getDomainObjects() as $domainObject2) { if ($domainObject2->getParentClass() === $domainObject1->getFullQualifiedClassName()) { $domainObject1->addChildObject($domainObject2); } } } } // relations if (is_array($extensionBuildConfiguration['wires'])) { $this->setExtensionRelations($extensionBuildConfiguration, $extension); } return $extension; }
/** * 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); } } } } }