Skip to content

Update name of arguments in interface DataMapperInterface methods #11794

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
Jun 27, 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
20 changes: 10 additions & 10 deletions form/data_mappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,38 @@ in your form type::
// ...

/**
* @param Color|null $data
* @param Color|null $viewData
*/
public function mapDataToForms($data, $forms)
public function mapDataToForms($viewData, $forms)
{
// there is no data yet, so nothing to prepopulate
if (null === $data) {
if (null === $viewData) {
return;
}

// invalid data type
if (!$data instanceof Color) {
throw new UnexpectedTypeException($data, Color::class);
if (!$viewData instanceof Color) {
throw new UnexpectedTypeException($viewData, Color::class);
}

/** @var FormInterface[] $forms */
$forms = iterator_to_array($forms);

// initialize form field values
$forms['red']->setData($data->getRed());
$forms['green']->setData($data->getGreen());
$forms['blue']->setData($data->getBlue());
$forms['red']->setData($viewData->getRed());
$forms['green']->setData($viewData->getGreen());
$forms['blue']->setData($viewData->getBlue());
}

public function mapFormsToData($forms, &$data)
public function mapFormsToData($forms, &$viewData)
{
/** @var FormInterface[] $forms */
$forms = iterator_to_array($forms);

// as data is passed by reference, overriding it will change it in
// the form object as well
// beware of type inconsistency, see caution below
$data = new Color(
$viewData = new Color(
$forms['red']->getData(),
$forms['green']->getData(),
$forms['blue']->getData()
Expand Down