Skip to content

[3.0] [Form] Map data to parent form data before POST_SUBMIT #8737

Closed
@webmozart

Description

@webmozart

Right now when submitting a form, all child forms are first submitted, then the data of these child forms is mapped back into the parent data by the parent form.

Shifting the mapping logic into the child form before POST_SUBMIT would make it possible to access changed state in the parent data in POST_SUBMIT listeners. For example:

$updateOnlinePayment = function (FormEvent $event) {
    $form = $event->getForm()->getParent();
    $order = $form->getData();

    $form->add('paymentMethod', 'choice', array(
        'disabled' => !$order->isOnlinePaymentSupported(),
    ));
}

$builder->get('country')->addEventListener(FormEvents::POST_SET_DATA, $updateOnlinePayment);
$builder->get('country')->addEventListener(FormEvents::POST_SUBMIT, $updateOnlinePayment);

Related to #5807.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions