During a simple project, I found that there were not any bundle providing the Multiple Step Form feature. Actually, I found one, https://github.com/craue/CraueFormFlowBundle . But for me, this bundle focuses too much on the Forms themselves, which was not relevant to me. For instance, I don't use to handle Form Event. Then, I came to the idea I could create a bundle which let developper interact with each form separately and then use a little well-configured system to manage the set of forms, the transitions between them, hydratation, ...
Therefore I created the MSFBundle. It's a little one with currently 5 or 6 classes and works out as a service. Its usage is very similar to form themselves to reduce learning time.
Bonus : with this system, it's easy to manage transitions even between MSF. You just have to configure actions at each step.
//loading MSFDataLoader entity
$msfdataloader = $this->getDoctrine()->getRepository('AppBundle:MSF\MSFDataLoader')
->findOneBy(['id'=>1]);
//using MSF service
$msf = $this->container->get('msf.registration');
// setting the specific MSFDataLoader to use
$msf->setMsfDataLoader($msfdataloader);
// OR if the loader doesn't exist yet
// $msf->init(new MSFDataLoader(), 'username');
//similar to the native usage of symfony 3 forms
$msf_form = $msf->getForm(); //FormInterface
$msf_form->handleRequest($request);
if($msf_form->isSubmitted() && $msf_form->isValid() ){
//for instance, persist entity
//you can also use configuration to set a callback to use for the form validation
//go to the following form or be redirected to configurated location
$msf->done();
}
return $this->render('MSF/default.html.twig', [
'form' => $msf_form->createView()
]);
- Symfony 3
- JMS Serializer (Need to install JMS)
- Doctrine Orm Entity Manager
- Router
- Request Stack
- Form Factory
- Buttons configuration (previous, next, cancel)
I have not studied performance yet. My main doubt is about use of Serializer. To make easy the use of my service, I let developpers define their own validation methods. To do that, they need to access the whole MSF Data which is stored as a JSON string and to deserialize it.
- You can attach one of your entities to a MSFDataLoader For instance, let create a MSF form to manage user registration. Let say the msf contains user, contact and role forms. You can add a MSFDataLoader field to your user entity. To dynamically attach the created user to this msfdataloader, go to the validation method of the 'user' configuration ( see method configure() ), set the field on the user object and then persist the user.