craue / CraueFormFlowBundle

Multi-step forms for your Symfony project.
MIT License
736 stars 118 forks source link

Passing options to current form #244

Closed Triodes closed 8 years ago

Triodes commented 8 years ago

When creating a form in a controller I can pass options to the specified form like this: $this->createForm(new MyForm(), $data, $options) Right now this is not possible in the form flow without setting those options for every form in the flow. (by using setGenericFormOptions)

I've looked through the code and it seems like the only thing needed to add this functionality is the following change in FormFlow.php (and it's respective interface):

public function createForm() {
    $form = $this->createFormForStep($this->currentStepNumber);

to:

public function createForm($options = null) {
    $form = $this->createFormForStep($this->currentStepNumber, $options);

I'm happy to submit this as a pull request but I'm not entirely sure this works. So I thought i would post it as an issue first.

craue commented 8 years ago

The options argument has been removed intentionally in #104. Also see #240.

Triodes commented 8 years ago

I see. Thank you for responding. I have read the mentioned issues but I do not see any way to pass any information to the forms from the controller. Do you have any suggestions?

edit: I wish to pass said data to 1 of the flow forms, not to all of them. So setGenericFormOptions doesn't really do the trick.

craue commented 8 years ago

You could add a property to your data object, override getFormOptions, and pass the value of that property as an option to the desired step, https://github.com/craue/CraueFormFlowBundle#passing-step-based-options-to-the-form-type.

Triodes commented 8 years ago

I can live with that. Thanks for the help.