Skip to content

[Form] Removed sidebar about Stateful data mappers #12468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions form/data_mappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,3 @@ create a new ``Color`` object now.

When a form has the ``inherit_data`` option set to ``true``, it does not use the data mapper and
lets its parent map inner values.

.. sidebar:: Stateful Data Mappers

Sometimes, data mappers need to access services or need to maintain their
state. In this case, you cannot implement the methods in the form type
itself. Create a separate class implementing ``DataMapperInterface`` and
initialize it in your form type::

// src/AppBundle/Form/Type/ColorType.php

// ...
use AppBundle\Form\DataMapper\ColorMapper;

final class ColorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ...

// Initialize the data mapper class and e.g. pass some state
->setDataMapper(new ColorMapper($options['opacity']))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also it isn't the best example, you can access to any form option from the data mapper methods through the parent form of the children.

;
}

// ...
}