This version comes with two changes which allow you to remove some superfluous code from your flows, form types, and templates:
- The step number is automatically added as option
flow_step
to forms. So you can remove all the code to manually set this option (which was calledflowStep
in the docs before) and just use the new option instead. - The hidden step field is automatically added to the form. So you don't need to include the bundle's template for it.
-
In method
loadStepsConfig
, thetype
option doesn't need to be set on empty steps anymore just to avoid an exception.before:
protected function loadStepsConfig() { return array( // ... array( 'label' => 'confirmation', 'type' => $this->formType, // needed to avoid InvalidOptionsException regarding option 'flowStep' ), ); }
after:
protected function loadStepsConfig() { return array( // ... array( 'label' => 'confirmation', ), ); }
-
In method
getFormOptions
, theflowStep
option doesn't need to be set manually anymore.before:
public function getFormOptions($step, array $options = array()) { $options = parent::getFormOptions($step, $options); $options['flowStep'] = $step; // ... return $options; }
after:
public function getFormOptions($step, array $options = array()) { $options = parent::getFormOptions($step, $options); // ... return $options; }
If method
getFormOptions
was only overridden to set this option, it can be removed altogether.
-
In method
setDefaultOptions
, you don't have to set theflowStep
option anymore.before:
public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'flowStep' => null, // ... )); }
after:
public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( // ... )); }
If method
setDefaultOptions
was only overridden to set this option, it can be removed altogether. -
In method
buildForm
, you can use the automatically set optionflow_step
now.before:
public function buildForm(FormBuilderInterface $builder, array $options) { switch ($options['flowStep']) { // ... } }
after:
public function buildForm(FormBuilderInterface $builder, array $options) { switch ($options['flow_step']) { // ... } }
-
Including the template
CraueFormFlowBundle:FormFlow:stepField.html.twig
is no longer needed.before:
<form method="post" {{ form_enctype(form) }}> {% include 'CraueFormFlowBundle:FormFlow:stepField.html.twig' %} {{ form_errors(form) }} {{ form_rest(form) }} {% include 'CraueFormFlowBundle:FormFlow:buttons.html.twig' %} </form>
after:
<form method="post" {{ form_enctype(form) }}> {{ form_errors(form) }} {{ form_rest(form) }} {% include 'CraueFormFlowBundle:FormFlow:buttons.html.twig' %} </form>