/** * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject * @return void */ protected function addInitStorageObjectCalls(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject) { $anyToManyRelationProperties = $domainObject->getAnyToManyRelationProperties(); if (count($anyToManyRelationProperties) > 0) { if (!$this->classObject->methodExists('__construct')) { $constructorMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method('__construct'); //$constructorMethod->setDescription('The constructor of this '.$domainObject->getName()); if (count($anyToManyRelationProperties) > 0) { $constructorMethod->setBody($this->codeGenerator->getDefaultMethodBody($domainObject, NULL, 'Model', '', 'construct')); } $constructorMethod->addModifier('public'); $constructorMethod->setTag('return', 'void'); $this->classObject->addMethod($constructorMethod); } $constructorMethod = $this->classObject->getMethod('__construct'); if (preg_match('/\\$this->initStorageObjects()/', $constructorMethod->getBody()) < 1) { t3lib_div::devLog('Constructor method in Class ' . $this->classObject->getName() . ' was overwritten since the initStorageObjectCall was missing', 'extension_builder', 2, array('Original method' => $constructorMethod->getBody())); $constructorMethod->setBody($this->initStorageObjectCall); $this->classObject->setMethod($constructorMethod); } //initStorageObjects $initStorageObjectsMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method('initStorageObjects'); $initStorageObjectsMethod->setDescription('Initializes all Tx_Extbase_Persistence_ObjectStorage properties.'); $methodBody = "/**\n* Do not modify this method!\n* It will be rewritten on each save in the extension builder\n* You may modify the constructor of this class instead\n*/\n"; foreach ($anyToManyRelationProperties as $relationProperty) { $methodBody .= "\$this->" . $relationProperty->getName() . " = new Tx_Extbase_Persistence_ObjectStorage();\n"; } $initStorageObjectsMethod->setBody($this->codeGenerator->getDefaultMethodBody($domainObject, NULL, 'Model', '', 'initStorageObjects')); $initStorageObjectsMethod->addModifier('protected'); $initStorageObjectsMethod->setTag('return', 'void'); $this->classObject->setMethod($initStorageObjectsMethod); } else { if ($this->classObject->methodExists('initStorageObjects')) { $this->classObject->getMethod('initStorageObjects')->setBody('// empty'); } } }