What is Form Context in Symfony2 What is Form Context in Symfony2 symfony symfony

What is Form Context in Symfony2


form.context service is a Symfony\Component\Form\FormContext object by default. Here's a full definition of this service:

    <service id="form.context" class="%form.context.class%">        <argument type="collection">            <argument key="validator" type="service" id="validator" />            <argument key="validation_groups">%form.validation_groups%</argument>            <argument key="field_factory" type="service" id="form.field_factory" />            <argument key="csrf_protection">%form.csrf_protection.enabled%</argument>            <argument key="csrf_field_name">%form.csrf_protection.field_name%</argument>            <argument key="csrf_provider" type="service" id="form.csrf_provider" />        </argument>    </service>

Actually it's a very simple object that just prepare some basic options used by almost every form, ie. a validator, CSRF protection and field factory.

In fact the code you've posted is equivalent of:

$form = new \Symfony\Components\Form\Form(null, array(    'validator' => $this->get('validator'),    'validation_groups' => ...    ...));