Skip to content

Commit 20c02a7

Browse files
committed
Merge pull request symfony#26 from vicb/form_review2
[Form] Remove usages of deprecated features
2 parents e18830d + 27151df commit 20c02a7

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
144144
$view->setVar('type', 'date');
145145
}
146146

147-
if ($view->hasChildren()) {
147+
if (count($view) > 0) {
148148
$pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
149149

150150
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
159159
}
160160

161161
return function (FormInterface $form) {
162-
if ($form->hasChildren()) {
162+
if (count($form) > 0) {
163163
return array();
164164
}
165165

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
6666
$data = $options['csrf_provider']->generateCsrfToken($options['intention']);
6767

6868
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array(
69-
'property_path' => false,
69+
'mapped' => false,
7070
));
7171

7272
$view->add($csrfForm->createView($view));

src/Symfony/Component/Form/Form.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public function bindRequest(Request $request)
588588
// Form bound without name
589589
$params = $request->request->all();
590590
$files = $request->files->all();
591-
} elseif ($this->hasChildren()) {
591+
} elseif (count($this->children) > 0) {
592592
// Form bound with name and children
593593
$params = $request->request->get($name, array());
594594
$files = $request->files->get($name, array());
@@ -757,14 +757,12 @@ public function getErrorsAsString($level = 0)
757757
$errors .= str_repeat(' ', $level).'ERROR: '.$error->getMessage()."\n";
758758
}
759759

760-
if ($this->hasChildren()) {
761-
foreach ($this->children as $key => $child) {
762-
$errors .= str_repeat(' ', $level).$key.":\n";
763-
if ($err = $child->getErrorsAsString($level + 4)) {
764-
$errors .= $err;
765-
} else {
766-
$errors .= str_repeat(' ', $level + 4)."No errors\n";
767-
}
760+
foreach ($this->children as $key => $child) {
761+
$errors .= str_repeat(' ', $level).$key.":\n";
762+
if ($err = $child->getErrorsAsString($level + 4)) {
763+
$errors .= $err;
764+
} else {
765+
$errors .= str_repeat(' ', $level + 4)."No errors\n";
768766
}
769767
}
770768

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public function testErrorBubblingIfCompound()
535535
'compound' => true,
536536
));
537537

538-
$this->assertTrue($form->getErrorBubbling());
538+
$this->assertTrue($form->getConfig()->getErrorBubbling());
539539
}
540540

541541
public function testNoErrorBubblingIfNotCompound()
@@ -544,7 +544,7 @@ public function testNoErrorBubblingIfNotCompound()
544544
'compound' => false,
545545
));
546546

547-
$this->assertFalse($form->getErrorBubbling());
547+
$this->assertFalse($form->getConfig()->getErrorBubbling());
548548
}
549549

550550
public function testOverrideErrorBubbling()
@@ -554,7 +554,7 @@ public function testOverrideErrorBubbling()
554554
'error_bubbling' => true,
555555
));
556556

557-
$this->assertTrue($form->getErrorBubbling());
557+
$this->assertTrue($form->getConfig()->getErrorBubbling());
558558
}
559559

560560
public function testPropertyPath()

src/Symfony/Component/Form/Tests/FormTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function testAdd()
376376
$this->form->add($child);
377377

378378
$this->assertSame($this->form, $child->getParent());
379-
$this->assertSame(array('foo' => $child), $this->form->getChildren());
379+
$this->assertSame(array('foo' => $child), $this->form->all());
380380
}
381381

382382
/**
@@ -440,7 +440,7 @@ public function testIterator()
440440
$this->form->add($this->getBuilder('foo')->getForm());
441441
$this->form->add($this->getBuilder('bar')->getForm());
442442

443-
$this->assertSame($this->form->getChildren(), iterator_to_array($this->form));
443+
$this->assertSame($this->form->all(), iterator_to_array($this->form));
444444
}
445445

446446
public function testBound()
@@ -1104,59 +1104,59 @@ public function testCreateView()
11041104
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11051105
$calls[] = 'type1::buildView';
11061106
$test->assertTrue($view->hasParent());
1107-
$test->assertFalse($view->hasChildren());
1107+
$test->assertEquals(0, count($view));
11081108
}));
11091109

11101110
$type1Extension->expects($this->once())
11111111
->method('buildView')
11121112
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11131113
$calls[] = 'type1ext::buildView';
11141114
$test->assertTrue($view->hasParent());
1115-
$test->assertFalse($view->hasChildren());
1115+
$test->assertEquals(0, count($view));
11161116
}));
11171117

11181118
$type2->expects($this->once())
11191119
->method('buildView')
11201120
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11211121
$calls[] = 'type2::buildView';
11221122
$test->assertTrue($view->hasParent());
1123-
$test->assertFalse($view->hasChildren());
1123+
$test->assertEquals(0, count($view));
11241124
}));
11251125

11261126
$type2Extension->expects($this->once())
11271127
->method('buildView')
11281128
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11291129
$calls[] = 'type2ext::buildView';
11301130
$test->assertTrue($view->hasParent());
1131-
$test->assertFalse($view->hasChildren());
1131+
$test->assertEquals(0, count($view));
11321132
}));
11331133

11341134
$type1->expects($this->once())
11351135
->method('finishView')
11361136
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11371137
$calls[] = 'type1::finishView';
1138-
$test->assertTrue($view->hasChildren());
1138+
$test->assertGreaterThan(0, count($view));
11391139
}));
11401140

11411141
$type1Extension->expects($this->once())
11421142
->method('finishView')
11431143
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11441144
$calls[] = 'type1ext::finishView';
1145-
$test->assertTrue($view->hasChildren());
1145+
$test->assertGreaterThan(0, count($view));
11461146
}));
11471147

11481148
$type2->expects($this->once())
11491149
->method('finishView')
11501150
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11511151
$calls[] = 'type2::finishView';
1152-
$test->assertTrue($view->hasChildren());
1152+
$test->assertGreaterThan(0, count($view));
11531153
}));
11541154

11551155
$type2Extension->expects($this->once())
11561156
->method('finishView')
11571157
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
11581158
$calls[] = 'type2ext::finishView';
1159-
$test->assertTrue($view->hasChildren());
1159+
$test->assertGreaterThan(0, count($view));
11601160
}));
11611161

11621162
$form = $this->getBuilder()->setTypes(array($type1, $type2))->getForm();

0 commit comments

Comments
 (0)