/**
  * 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 $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;
 }
Beispiel #3
0
 /**
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\AbstractRelation $domainProperty
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method
  */
 protected function buildRemoveMethod($domainProperty)
 {
     $propertyName = $domainProperty->getName();
     $removeMethodName = self::getMethodName($domainProperty, 'remove');
     $parameterName = \EBT\ExtensionBuilder\Utility\Tools::getParameterName($domainProperty, 'remove');
     if ($this->classObject->methodExists($removeMethodName)) {
         $removeMethod = $this->classObject->getMethod($removeMethodName);
     } else {
         $removeMethod = clone $this->templateClassObject->getMethod('removeChild');
         $removeMethod->setName('remove' . ucfirst(\EBT\ExtensionBuilder\Utility\Inflector::singularize($propertyName)));
         $removeMethod->setTag('param', \EBT\ExtensionBuilder\Utility\Tools::getParamTag($domainProperty, 'remove'), true);
         $removeMethod->setTag('return', 'void');
         $removeMethod->addModifier('public');
         $removeMethod->getParameterByPosition(0)->setName($parameterName)->setVarType($domainProperty->getForeignClassName())->setTypeHint($domainProperty->getForeignClassName());
         $removeMethod->updateParamTags();
         $this->updateMethodBody($removeMethod, array('childToRemove' => $parameterName, 'child' => $domainProperty->getForeignModelName(), 'children' => $propertyName, 'Child' => $domainProperty->getForeignModelName()));
         $this->updateDocComment($removeMethod, array('\\bchildToRemove\\b' => $parameterName, '\\bChild\\b' => $domainProperty->getForeignModelName()));
     }
     $removeParameters = $removeMethod->getParameterNames();
     if (!in_array(\EBT\ExtensionBuilder\Utility\Tools::getParameterName($domainProperty, 'remove'), $removeParameters)) {
         $removeParameter = new Model\ClassObject\MethodParameter(\EBT\ExtensionBuilder\Utility\Tools::getParameterName($domainProperty, 'remove'), true);
         $removeParameter->setName(\EBT\ExtensionBuilder\Utility\Tools::getParameterName($domainProperty, 'remove'))->setVarType($domainProperty->getForeignClassName())->setTypeHint($domainProperty->getForeignClassName())->setTypeForParamTag($domainProperty->getTypeForComment());
         $removeMethod->setParameter($removeParameter);
     }
     if (!$removeMethod->hasDescription()) {
         $removeMethod->setDescription('Removes a ' . $domainProperty->getForeignModelName());
     }
     return $removeMethod;
 }
 /**
  *
  * @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']);
         }
     }
     return $relation;
 }
 /**
  * Builds a method that checks the current boolean state of a property
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\AbstractProperty $domainProperty
  *
  * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method
  */
 protected function buildIsMethod($domainProperty)
 {
     $isMethodName = \EBT\ExtensionBuilder\Utility\Tools::getMethodName($domainProperty, 'is');
     if ($this->classObject->methodExists($isMethodName)) {
         $isMethod = $this->classObject->getMethod($isMethodName);
     } else {
         $isMethod = clone $this->templateClassObject->getMethod('isProperty');
         $isMethod->setName('is' . ucfirst($domainProperty->getName()));
         $isMethod->setTag('return', 'boolean');
         $replacements = array('property' => $domainProperty->getName());
         $this->updateMethodBody($isMethod, $replacements);
         $this->updateDocComment($isMethod, $replacements);
     }
     if (!$isMethod->hasDescription()) {
         $isMethod->setDescription('Returns the boolean state of ' . $domainProperty->getName());
     }
     return $isMethod;
 }