Skip to content

Commit 889a160

Browse files
author
Bernhard Schussek
committed
[Form] Merged Field and Form. Merged FieldBuilder and FormBuilder. After the refactoring, the distinction between the two concepts is small enough to merge them
1 parent b620dc6 commit 889a160

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+993
-1148
lines changed

DataMapper/DataMapperInterface.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
namespace Symfony\Component\Form\DataMapper;
1313

14-
use Symfony\Component\Form\FieldInterface;
1514
use Symfony\Component\Form\FormInterface;
1615

1716
interface DataMapperInterface
1817
{
1918
function createEmptyData();
2019

21-
function mapDataToForm(&$data, FormInterface $form);
20+
function mapDataToForms($data, array $forms);
2221

23-
function mapDataToField(&$data, FieldInterface $field);
22+
function mapDataToForm($data, FormInterface $form);
2423

25-
function mapFormToData(FormInterface $form, &$data);
24+
function mapFormsToData(array $forms, &$data);
2625

27-
function mapFieldToData(FieldInterface $field, &$data);
26+
function mapFormToData(FormInterface $field, &$data);
2827
}

DataMapper/PropertyPathMapper.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Form\DataMapper;
1313

14-
use Symfony\Component\Form\FieldInterface;
1514
use Symfony\Component\Form\FormInterface;
1615
use Symfony\Component\Form\RecursiveFieldIterator;
1716
use Symfony\Component\Form\Exception\FormException;
@@ -51,7 +50,7 @@ public function createEmptyData()
5150
return array();
5251
}
5352

54-
public function mapDataToForm(&$data, FormInterface $form)
53+
public function mapDataToForms($data, array $forms)
5554
{
5655
if (!empty($data) && !is_array($data) && !is_object($data)) {
5756
throw new \InvalidArgumentException(sprintf('Expected argument of type object or array, %s given', gettype($data)));
@@ -62,49 +61,51 @@ public function mapDataToForm(&$data, FormInterface $form)
6261
throw new FormException(sprintf('Form data should be instance of %s', $this->dataClass));
6362
}
6463

65-
$iterator = new RecursiveFieldIterator($form);
64+
$iterator = new RecursiveFieldIterator($forms);
6665
$iterator = new \RecursiveIteratorIterator($iterator);
6766

68-
foreach ($iterator as $field) {
69-
$this->mapDataToField($data, $field);
67+
foreach ($iterator as $form) {
68+
$this->mapDataToForm($data, $form);
7069
}
7170
}
7271
}
7372

74-
public function mapDataToField(&$data, FieldInterface $field)
73+
public function mapDataToForm($data, FormInterface $form)
7574
{
76-
if ($field->getAttribute('property_path') !== null) {
77-
$field->setData($field->getAttribute('property_path')->getValue($data));
75+
if (!empty($data)) {
76+
if ($form->getAttribute('property_path') !== null) {
77+
$form->setData($form->getAttribute('property_path')->getValue($data));
78+
}
7879
}
7980
}
8081

81-
public function mapFormToData(FormInterface $form, &$data)
82+
public function mapFormsToData(array $forms, &$data)
8283
{
83-
$iterator = new RecursiveFieldIterator($form);
84+
$iterator = new RecursiveFieldIterator($forms);
8485
$iterator = new \RecursiveIteratorIterator($iterator);
8586

86-
foreach ($iterator as $field) {
87+
foreach ($iterator as $form) {
8788
$isReference = false;
8889

8990
// If the data is identical to the value in $data, we are
9091
// dealing with a reference
91-
if ($field->getAttribute('property_path') !== null) {
92-
$isReference = $field->getData() === $field->getAttribute('property_path')->getValue($data);
92+
if ($form->getAttribute('property_path') !== null) {
93+
$isReference = $form->getData() === $form->getAttribute('property_path')->getValue($data);
9394
}
9495

9596
// Don't write into $data if $data is an object,
9697
// $isReference is true (see above) and the option "by_reference" is
9798
// true as well
98-
if (!is_object($data) || !$isReference || !$field->getAttribute('by_reference')) {
99-
$this->mapFieldToData($field, $data);
99+
if (!is_object($data) || !$isReference || !$form->getAttribute('by_reference')) {
100+
$this->mapFormToData($form, $data);
100101
}
101102
}
102103
}
103104

104-
public function mapFieldToData(FieldInterface $field, &$data)
105+
public function mapFormToData(FormInterface $form, &$data)
105106
{
106-
if ($field->getAttribute('property_path') !== null) {
107-
$field->getAttribute('property_path')->setValue($data, $field->getData());
107+
if ($form->getAttribute('property_path') !== null) {
108+
$form->getAttribute('property_path')->setValue($data, $form->getData());
108109
}
109110
}
110111
}

Event/DataEvent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
namespace Symfony\Component\Form\Event;
44

55
use Symfony\Component\EventDispatcher\Event;
6-
use Symfony\Component\Form\FieldInterface;
6+
use Symfony\Component\Form\FormInterface;
77

88
class DataEvent extends Event
99
{
1010
private $field;
1111

1212
protected $data;
1313

14-
public function __construct(FieldInterface $field, $data)
14+
public function __construct(FormInterface $field, $data)
1515
{
1616
$this->field = $field;
1717
$this->data = $data;

EventListener/FixFileUploadListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\EventListener;
1313

14-
use Symfony\Component\Form\FieldInterface;
14+
use Symfony\Component\Form\FormInterface;
1515
use Symfony\Component\Form\Events;
1616
use Symfony\Component\Form\Event\FilterDataEvent;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

EventListener/FixRadioInputListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\EventListener;
1313

14-
use Symfony\Component\Form\FieldInterface;
14+
use Symfony\Component\Form\FormInterface;
1515
use Symfony\Component\Form\Events;
1616
use Symfony\Component\Form\Event\FilterDataEvent;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

EventListener/FixUrlProtocolListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\EventListener;
1313

14-
use Symfony\Component\Form\FieldInterface;
14+
use Symfony\Component\Form\FormInterface;
1515
use Symfony\Component\Form\Events;
1616
use Symfony\Component\Form\Event\FilterDataEvent;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

EventListener/ResizeFormListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
use Symfony\Component\Form\Events;
1515
use Symfony\Component\Form\Event\DataEvent;
16-
use Symfony\Component\Form\FormInterface;
1716
use Symfony\Component\Form\FormFactoryInterface;
18-
use Symfony\Component\Form\FieldInterface;
17+
use Symfony\Component\Form\FormInterface;
1918
use Symfony\Component\Form\Exception\UnexpectedTypeException;
2019
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2120

0 commit comments

Comments
 (0)