.. index::
    double: Api; Definition

Api
===

The bundle comes with an handy ``FormHelper::removeField`` method which can be used to remove form's fields
if the related submitted data is not provided. The Form Component's default behavior is to set ``null`` if a form
field is defined but no data submitted for this particular field. This is quite annoying while building an API and the
client only sent partial data to update an entity.

.. code-block:: php

    <?php

    $category = $id ? $this->getCategory($id) : null;

    $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_category', $category, array(
        'csrf_protection' => false
    ));

    FormHelper::removeFields($request->request->all(), $form);

    $form->bind($request);

    if ($form->isValid()) {
        // ...
    }

The call need to.. index::
    single: Installation

Installation
============

* Add ``SonataCoreBundle`` to your ``vendor/bundles`` directory with the `deps` file:

.. code-block:: json

    // composer.json

    "require": {
    //...
        "sonata-project/core-bundle": "~2.2@dev",
    //...
    }


* Add ``SonataCoreBundle`` to your application kernel:

.. code-block:: php

    <?php

    // app/AppKernel.php

    public function registerBundles()
    {
        return array(
            // ...
            new Sonata\CoreBundle\SonataCoreBundle(),
            // ...
        );
    }

* Create a configuration file ``sonata_core.yml`` with this content:

.. code-block:: yaml

    sonata_core: ~

* Update the ``config.yml`` with the new resource to import:

.. code-block:: yaml

    imports:
        #...
        - { resource: sonata_core.yml }
