[TYPO3-mvc] Model object tree building with Tx_Extbase_Persistence_ObjectStorage property

Claus Fassing claus at fassing.eu
Mon Sep 27 22:56:55 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Franz,

thank you for your help.

Am 26.09.2010 19:02, schrieb Franz Koch:
> 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);
> }

The objectManager don't contain any object. So I just try this.

if (!$entry->getCompany()->getContact()->count()) {
 	$contact = t3lib_div::makeInstance('Tx_Myext_Domain_Model_Person');
  $entry->getCompany()->addContact($contact);
}

Looks from debugging view that company now contain a person object.


> 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>

But in the view company.contact is empty, no iteration

> 
> 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"/>

and no contact.uid available oO
Is my way of creating dummy person object wrong ? But what else I can do
if $this->objectManager->getObject won't work ?

There is another strange thing. If I instance [1] the entry object, the
company object is missing also (watching from debug). I have to instance
the company object explicit in the entry constructor
$this->setCompany(new Tx_Myext_Domain_Model_Company());
No lazy loading annotations given.

> This should work, as I used it lately for creating a form for
> dynamically adding query/filter-options to a list view.
> 

What can be the different to my form ?

Regards Claus

[1]
public function newAction(Tx_Myext_Domain_Model_Offer $entry = NULL) {
  if($entry == NULL){
    $entry = t3lib_div::makeInstance('Tx_Myext_Domain_Model_Entry');
  }
  $this->view->assign('entry', $entry);
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMoQUXAAoJELsIv+audObf/EsIALCvOXwzl2WDaO+fXHwfqV1C
90W/aubZYdoH3e4CHDNiRU55nPv8a8qS++QflqiSBLwgQRbhyBl6L7IJoSEgdARw
R1GN196SNH9LYVcX70Ot9bEbL/04odI2jlRwLLpOMsWid4UdrsY4Bpa5Uhg0UY1y
xaPF7XHPIexrYGvETbSfM8J5ZaS7qjAYYFSpnw2NnyYgfThxARGUAphmSx5IHUU3
z+1sXcjwXWDv02QDY6AdThKbDlRAsfcraZnwzkZSmU/pe5cIsZlDrn9c7Ha1uIzt
k+qyWKvxWC2Kh82evpaslL7L1ma1NxQNGYX0HaYUR98WiTRfBpKSlwdDugNQjLU=
=SjRu
-----END PGP SIGNATURE-----


More information about the TYPO3-project-typo3v4mvc mailing list