8000 [2.3] [Form] Renamed option "virtual" to "inherit_data" and improved handling of such forms by webmozart · Pull Request #6573 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.3] [Form] Renamed option "virtual" to "inherit_data" and improved handling of such forms #6573

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 3 commits into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[Form] Moved parent data inheritance from data mappers to Form
  • Loading branch information
webmozart committed Apr 19, 2013
commit ac2ca44b5ac33e66d2f951ea7020503d3d9f0340
3 changes: 3 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ CHANGELOG
* deprecated passing a Request instance to FormInterface::bind()
* added options "method" and "action" to FormType
* deprecated option "virtual", renamed it to "inherit_data"
* deprecated VirtualFormAwareIterator in favor of InheritDataAwareIterator
* [BC BREAK] removed the "array" type hint from DataMapperInterface
* improved forms inheriting their parent data to actually return that data from getData(), getNormData() and getViewData()

2.2.0
-----
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Form/DataMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ interface DataMapperInterface
/**
* Maps properties of some data to a list of forms.
*
* @param mixed $data Structured data.
* @param array $forms A list of {@link FormInterface} instances.
* @param mixed $data Structured data.
* @param FormInterface[] $forms A list of {@link FormInterface} instances.
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
*/
public function mapDataToForms($data, array $forms);
public function mapDataToForms($data, $forms);

/**
* Maps the data of a list of forms into the properties of some data.
*
* @param array $forms A list of {@link FormInterface} instances.
* @param mixed $data Structured data.
* @param FormInterface[] $forms A list of {@link FormInterface} instances.
* @param mixed $data Structured data.
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
*/
public function mapFormsToData(array $forms, &$data);
public function mapFormsToData($forms, &$data);
}
21 changes: 21 additions & 0 deletions src/Symfony/Component/Form/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Exception;

/**
* Base RuntimeException for the Form component.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form\Extension\Core\DataMapper;

use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Util\VirtualFormAwareIterator;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
Expand Down Expand Up @@ -42,7 +41,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
/**
* {@inheritdoc}
*/
public function mapDataToForms($data, array $forms)
public function mapDataToForms($data, $forms)
{
if (null === $data || array() === $data) {
return;
Expand All @@ -52,11 +51,7 @@ public function mapDataToForms($data, array $forms)
throw new UnexpectedTypeException($data, 'object, array or empty');
}

$iterator = new VirtualFormAwareIterator($forms);
$iterator = new \RecursiveIteratorIterator($iterator);

foreach ($iterator as $form) {
/* @var \Symfony\Component\Form\FormInterface $form */
foreach ($forms as $form) {
$propertyPath = $form->getPropertyPath();
$config = $form->getConfig();

Expand All @@ -69,7 +64,7 @@ public function mapDataToForms($data, array $forms)
/**
* {@inheritdoc}
*/
public function mapFormsToData(array $forms, &$data)
public function mapFormsToData($forms, &$data)
{
if (null === $data) {
return;
Expand All @@ -79,11 +74,7 @@ public function mapFormsToData(array $forms, &$data)
throw new UnexpectedTypeException($data, 'object, array or empty');
}

$iterator = new VirtualFormAwareIterator($forms);
$iterator = new \RecursiveIteratorIterator($iterator);

foreach ($iterator as $form) {
/* @var \Symfony\Component\Form\FormInterface $form */
foreach ($forms as $form) {
$propertyPath = $form->getPropertyPath();
$config = $form->getConfig();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Validator\ViolationMapper;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Util\VirtualFormAwareIterator;
use Symfony\Component\Form\Util\InheritDataAwareIterator;
use Symfony\Component\PropertyAccess\PropertyPathIterator;
use Symfony\Component\PropertyAccess\PropertyPathBuilder;
use Symfony\Component\PropertyAccess\PropertyPathIteratorInterface;
Expand Down Expand Up @@ -100,6 +100,9 @@ public function mapViolation(ConstraintViolation $violation, FormInterface $form
$scope = $form;
$it = new ViolationPathIterator($violationPath);

// Note: acceptsErrors() will always return true for forms inheriting
// their parent data, because these forms can never be non-synchronized
// (they don't do any data transformation on their own)
while ($this->acceptsErrors($scope) && $it->valid() && $it->mapsForm()) {
if (!$scope->has($it->current())) {
// Break if we find a reference to a non-existing child
Expand Down Expand Up @@ -164,7 +167,7 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $

// Skip forms inheriting their parent data when iterating the children
$childIterator = new \RecursiveIteratorIterator(
new VirtualFormAwareIterator($form->all())
new InheritDataAwareIterator($form->all())
);

// Make the path longer until we find a matching child
Expand Down
Loading
0