[TYPO3-dev] Getting persisted state of modified domain model

Philipp Schiffmann p.schiffmann at bitmotion.de
Thu Mar 12 13:44:02 CET 2015


Hi list,

I need to get the persisted state of an extbase model after it was modified
(but not persisted yet) during a request for the following reason:
I've got a model with a 1:n relation to files:

class MyModel {
/** @var ObjectStorage<FileReference> */
protected $attachments;

// ...
}

Now, I want to be able to delete these references from inside a Fluid form.
I do this by rendering the file reference as a checkbox:
<input name="my_pi[myModel][attachments][1][__identity]" type="checkbox"
value="42">

This way, when the form gets submitted, the deselected references won't be
added to the ObjectStorage during property mapping and ultimately get
removed. Until here it works just fine.

However, it gets problematic once a validation error occurs that forwards
me back to the fluid form, because the action that is forwarded to still
uses the modified object. That means that the attachments property only
contains those objects that were checked when the form was submitted.
However, I need to iterate over that property in Fluid to render the
checkboxes. So, every time a user deselects one of the references and then
makes a mistake that leads to a validation error, I render a shorter list
of attachments!

My idea is to use the persisted state of the object for the iteration – the
object has to be fetched from persistence during property mapping anyways,
so I guess it's still around somewhere, right? But if you have other ideas
how to solve this, I'd be happy to see them too!

Thanks in advance and best regards
Philipp



More information about the TYPO3-dev mailing list