[TYPO3-mvc] Model object tree building with Tx_Extbase_Persistence_ObjectStorage property
Franz Koch
typo3.RemoveForMessage at elements-net.de
Sun Sep 26 19:02:36 CEST 2010
Hey,
AFAIK rendering nested objects belonging to objectStorages are not yet
properly supported by Fluid yet.
>> Company
>> name (string)
>> contact (Tx_Extbase_Persistence_ObjectStorage of Person object)
>> [...]
...
>> <f:form method="post" action="create" name="entry" object="{entry}">
>> <f:form.textbox property="company.name" id="companyname" />
>> <f:form.textbox property="company.contact.forename" id="forename"/>
>> <f:form.textbox property="company.contact.lastname" id="lastname"/>
>> </f:form>
...
that can't work. Contact is a objectStorage, but you're building a form
field that's no reflecting this. In your case "forname" would be a
value/ID for a PersonObject as well as lastname.
> I can avoid the exception by using company.contact.0.forename for
> property, but this break the value recovery after redirect / forward
> from validator. Do anybody know why only these field values not get
> recovered ?
That's going in the right direction, but the problem now is, that "0" is
reflecting the UID/object-identifier - and once the object is created on
submit, the object-identifier won't match "0" again but be some
hash-value or if persisted a UID > 0.
Give the following a try in your controllers "form" action (so the
action rendering the initial form, not the one responsible to process
submitted form data):
if (!$entry->getCompany()->getContact()->count()) {
$dummyPerson = $this->objectManager->getObject('Person');
$entry->getCompany()->addContact($dummyPerson);
}
In your template you iterate over the person(s) then:
<f:for each="{company.contact}" as="contact">
<f:form.textbox property="company.contact.{contact.uid}.forename"
id="forename"/>
<f:form.textbox property="company.contact.{contact.uid}.lastname"
id="lastname"/>
</f:for>
Something like that should/could work - not tested though. If it's not
working by assigning this properties, you have to take care of the
correct form names yourself like this:
<f:form.textbox name="entry[company][contact][{contact.uid}][forname]"
value="{contact.forname} id="forename"/>
This should work, as I used it lately for creating a form for
dynamically adding query/filter-options to a list view.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list