[TYPO3-mvc] New Property Mapper / persisting nested form objects
Alexander Dick
typo3 at dick.at
Thu Jan 26 18:48:55 CET 2012
Hi everybody!
I am using Extbase 1.4, with the new property mapper enabled.
Persisting my nested form basically works, as I set
allowCreationForSubProperty() in the corresponding initializeAction:
public function initializeSaveAction() {
$this->arguments['parentObject']
->getPropertyMappingConfiguration()
->allowCreationForSubProperty('childObject');
}
BUT only if the childObject has a 1:1 relation with the parentObject /
is no Tx_Extbase_Persistence_ObjectStorage!
If I have a m:m relation between ParentObject and the childObject it
throws the well known "Exception while property mapping at property path
"childObjects.0":Creation of objects not allowed. To enable this, you
need to set the PropertyMappingConfiguration Value
"CONFIGURATION_CREATION_ALLOWED" to TRUE"
So what can I do about this?
Relevant model properties:
class Tx_Xxx_Domain_Model_ParentObject extends
Tx_Extbase_DomainObject_AbstractEntity {
/**
* Simple child object - everything works as expected
* @var Tx_Xxx_Domain_Model_ChildObject
*/
protected $childObject;
/**
* Multiple child objects - Exception...
*
* @var
Tx_Extbase_Persistence_ObjectStorage<Tx_Xxx_Domain_Model_ChildObject>
*/
protected $childObjects;
}
In case of the "array" of child objects,
my initializeAction looks like this:
public function initializeSaveAction() {
// does not have any effect - exception is thrown
$this->arguments['parentObject']
->getPropertyMappingConfiguration()
->allowCreationForSubProperty('childObjects');
// has no effect either,
// also tried setting allowCreationForSubProperty()
// for childObjects AND childObjects.childObject
$this->arguments['parentObject']
->getPropertyMappingConfiguration()
->allowCreationForSubProperty('childObjects.childObject');
}
The form fields look like this:
// simple relation - works
tx_xxx_controllername[parentObject][childObject][title]
// Persistence_ObjectStorage - does not work
tx_xxx_controllername[parentObject][childObjects][0][title]
Any hint would be highly appreciated, I'm really stuck here.
Thanks in advance,
Best regards
Alex
More information about the TYPO3-project-typo3v4mvc
mailing list