简体   繁体   中英

Symfony2 : form : pre_submit orders

I have 2 forms. One is the main form with fields and a collection and inside this fields the other form. On each form (the parent and the child) I add a PRE_SUBMIT subscriber. Now, my problem is, I want to load a method specific to the parent form after execution of the PRE_SUBMIT on the child event. Actually, following the documentation, in spite I give priority, I have always this order : parent::PRE_SUBMIT -> child::PRE_SUBMIT and by the way I want : parent::PRE_SUBMIT -> child::PRE_SUBMIT -> parent::PRE_SUBMIT(other) Do you have an idea if it's possible to do that and in what way ?

Remove the event PRE_SUBMIT on your children (only add it for the parent), and inside your event handler do the specific code for your children.

Eg

public function yourPresubmitMethod(FormEvent $event)
{
   $form = $event->getForm();

   // Code before

   // Code for each child
   foreach ($form as $child)
   {
      $child->theChildPreSubmitMethod();
   }

   // Code after
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM