[TYPO3-mvc] How to dynamically create objects

Nicolas de Haen typo3 at ndh-websolutions.de
Mon May 20 14:45:28 CEST 2013


Hi Joerg,

afaik there is only one (not quite comfortable) solution:

You have to allow explicitely each of your dynamic created properties in 
the controller initializeAction (or initializeCreateAction):

if($this->request->hasArgument('newOrder')) {
$newOrder = $this->request->getArgument('newOrder');
$propertyMappingConfiguration = 
$this->arguments->getArgument('newOrder')->getPropertyMappingConfiguration();

if(!empty($newOrder['positions'])) {
	$propertyMappingConfiguration->forProperty('positions')->allowAllProperties();
$propertyMappingConfiguration->allowModificationForSubProperty('positions');
						foreach($newOrder[$dynamicProperty] as
$positionIndex => $positionPropertyArray) {
$propertyPath = 'positions.' . $propertyIndex;			 
$propertyMappingConfiguration->forProperty($propertyPath)->allowAllProperties();
$propertyMappingConfiguration->allowCreationForSubProperty($propertyPath);
$propertyMappingConfiguration->allowModificationForSubProperty($propertyPath);

} // end foreach
} // end if(!empty)
} // end if(request->hasArgument)

Pretty much code for a task that should/could be done by the 
framework... ;-)

And it's getting really funny if you have nested properties..

BTW: as I mentioned in an earlier post, there is no chance to edit the 
positions after creating them, without a patch in ObjectAccess, allowing 
to access objects inside properties of type ObjectStorage

regards,
Nico

-- 
Nico de Haen
ndh websolutions

Webprogrammierung, OpenSource, Typo3



http://www.ndh-websolutions.de


More information about the TYPO3-project-typo3v4mvc mailing list