Discussion:
[TYPO3-english] TYPO3 extension thought experiment: Editing a news entry and comment entries in one go
christian ewigfrost
2018-01-31 08:03:58 UTC
Permalink
I have a class called news. This class of course has an edit and update Action in its specific controller. Next to this it has objects of the class comments attached to it (the relation to these comments objects is stored in an Object Storage). Normally, as you can imagine, you can edit the news and the comments seperately as they have seperate controllers and their Actions. BUT: Is there a way to edit the news object/record and the comments of it in one go hypothetically?
So basically the editAction of the news class assigns the news object with its corresponding Object Storage property "comments" to the view and in the view i can easily access each comment through their relation in the Object Storage and implement them into a form to also change their values...
The simplyfied updateAction would look like this (keep in mind the property "comments" of the news is the Object Storage for the comments):
public function updateAction(\...\...\Domain\Model\news $news)
{
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$commentRepository = $objectManager->get(\...\...\Domain\Repository\commentRepository::class);

foreach($news->getComments() as $comment){
$commentRepository->update($comment);
}

$this->newsRepository->update($news);
$this->redirect('list');
}
The (simplified) Edit template would look like this:
<f:form action="update" name="news" object="{news}" >

<f:form.textarea property="newsentry" cols="40" rows="15" /><br />

<f:for each="{news.comments}" as="comment" >
<f:form.textarea property="commententry" value="{comment.commententry}" /><br />
</f:for>

<f:form.submit value="Save" />
Do you see the problem in this hypothetical example? Only the news object is passed to the updateAction and of course the Object Storage property ("comments") where the relations to the corresponding comment objects are stored are passed to the updateAction, not the changed comments themselves. So only the changed newsentry is persisted not the changed commnetentries, even though i have the necessary code in the updateAction to do so.
So, guys... Is there any solution to this problem or is it not possible at all and i should look for other means to find a solution and don' waste time on this.
Loading...