Reputation: 1948
I use an eventlisterner to check some values returned by the user/author before actually submitting them to the DB.
My form allow ROLE_USERS to change some attribut (like statut) to the Entity Article. Article has attribute such as statut(Published, Delete) and tobecheked('author wants to delete this article', 'null') which allow ROLE_ADMIN to review easily some article.
Anyway. I want that when Author submit statut=>'DELETE' the value of statut tobechecked to be turned into => 'author wants to delete this article'.
Here what I tried but this is not working.
class Article extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('Statut', ...);
->add('toBeChecked', ...);
$dynamicSubmissionFunc = function (FormEvent $event)
{
$data = $event->getData();
if($data['statut'] == 'DELETE')
{
// HOW CAN I MODIFY HERE THE VALUE OF ARTICLE ATTRIBUTE
$data['toBeChecked'] = 'author wants to delete this article';
// nothing is changed in the attribute toBeChecked.
}
}
$builder->addEventListener(FormEvents::PRE_SUBMIT, $dynamicSubmissionFunc);
}
}
Upvotes: 1
Views: 4046
Reputation: 13240
Ok. I figured out. You need to set your data back to the event:
$event->setData($data);
Upvotes: 3