Pascals Blog

17.01.2010
17:39

Nested Objects with FLUID

A few days ago someone on the #TYPO3 IRC channel on Freenode had a problem submitting nested objects within his exbtase extension.

Imagine the following: you have a shopping cart object holding some items from the shop. Now the customer submits his order and changes the number of items he wants to buy. You obviously wouldn't want to click on the item first, change it's quantity, save that and then submit the shopping cart. The solution is to nest the objects and submit them.

So we fiddled a bit and came to a solution which is even quiet simple. Thomas was nice enough to share the solution on the mailing list. Unfortunately FLUID doesn't generate the correct form, so you have to do it yourself:

<f:form name="object" object="{object}" action="update">
<f:for each="{object.subObjects}" as="subObject">
<f:form.textbox name="subObjects[{subObject.uid}][title]"
    value="{subObject.title}"/>
<f:form.hidden name="subObjects[{subObject.uid}][__identity]"
    value="{subObject.uid}"/>
</f:for>
</f:form>

The basic point here is simply to provide the __identity property so that extbase is able to map the incomming object correctly. But there is one more problem: FLUID prevents you for security reasons to modify properties of objects which where not editable in the form. And as FLUID doesn't generate the above form, it would throw an error. So we have to disable this check. Please note that you should really know what you are doing, when disabling it.

/**
* Update
*
* @dontverifyrequesthash
* @param Tx_EXT_Domain_Model_Object $object
* @param array $subObjects
* @return void
*/
public function updateAction(
Tx_EXT_Domain_Model_Object $object,
  array $subObjects) {
$this->propertyMapper->map(
      array('subObjects'), array('subObjects' => $subObjects),
      $object
  );
}

The important parts here are the @dontverifyrequesthash which disables the hash checking for the reason I pointed out above. The map(); function automatically persists the changes an you're done.

  •  
  • 0 Comment(s)
  •  

Your comment

Notify me when someone adds another comment to this post

back

Latest Posts

Submit properties of properties
19.08.2010 10:36
Code and project management with InDefero
18.01.2010 01:59
Nested Objects with FLUID
17.01.2010 17:39
Welcome
16.01.2010 20:00

Categories

  • Development(1)
  • Stuff(1)
  • [-]TYPO3(4)
    • Extbase(2)
    • [-]FLUID(2)

Copy and paste this link into your RSS news reader

RSS 2.0Posts