[Form] Remove usages of deprecated features

This commit is contained in:
Victor Berchet 2012-05-25 08:38:37 +02:00 committed by Bernhard Schussek
parent ee803cd948
commit 3d800afec3
6 changed files with 23 additions and 25 deletions

View File

@ -144,7 +144,7 @@ class DateType extends AbstractType
$view->setVar('type', 'date'); $view->setVar('type', 'date');
} }
if ($view->hasChildren()) { if (count($view) > 0) {
$pattern = $form->getConfig()->getAttribute('formatter')->getPattern(); $pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy) // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)

View File

@ -159,7 +159,7 @@ class FormType extends AbstractType
} }
return function (FormInterface $form) { return function (FormInterface $form) {
if ($form->hasChildren()) { if (count($form) > 0) {
return array(); return array();
} }

View File

@ -66,7 +66,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
$data = $options['csrf_provider']->generateCsrfToken($options['intention']); $data = $options['csrf_provider']->generateCsrfToken($options['intention']);
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array( $csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array(
'property_path' => false, 'mapped' => false,
)); ));
$view->add($csrfForm->createView($view)); $view->add($csrfForm->createView($view));

View File

@ -588,7 +588,7 @@ class Form implements \IteratorAggregate, FormInterface
// Form bound without name // Form bound without name
$params = $request->request->all(); $params = $request->request->all();
$files = $request->files->all(); $files = $request->files->all();
} elseif ($this->hasChildren()) { } elseif (count($this->children) > 0) {
// Form bound with name and children // Form bound with name and children
$params = $request->request->get($name, array()); $params = $request->request->get($name, array());
$files = $request->files->get($name, array()); $files = $request->files->get($name, array());
@ -757,14 +757,12 @@ class Form implements \IteratorAggregate, FormInterface
$errors .= str_repeat(' ', $level).'ERROR: '.$error->getMessage()."\n"; $errors .= str_repeat(' ', $level).'ERROR: '.$error->getMessage()."\n";
} }
if ($this->hasChildren()) { foreach ($this->children as $key => $child) {
foreach ($this->children as $key => $child) { $errors .= str_repeat(' ', $level).$key.":\n";
$errors .= str_repeat(' ', $level).$key.":\n"; if ($err = $child->getErrorsAsString($level + 4)) {
if ($err = $child->getErrorsAsString($level + 4)) { $errors .= $err;
$errors .= $err; } else {
} else { $errors .= str_repeat(' ', $level + 4)."No errors\n";
$errors .= str_repeat(' ', $level + 4)."No errors\n";
}
} }
} }

View File

@ -535,7 +535,7 @@ class FormTypeTest extends TypeTestCase
'compound' => true, 'compound' => true,
)); ));
$this->assertTrue($form->getErrorBubbling()); $this->assertTrue($form->getConfig()->getErrorBubbling());
} }
public function testNoErrorBubblingIfNotCompound() public function testNoErrorBubblingIfNotCompound()
@ -544,7 +544,7 @@ class FormTypeTest extends TypeTestCase
'compound' => false, 'compound' => false,
)); ));
$this->assertFalse($form->getErrorBubbling()); $this->assertFalse($form->getConfig()->getErrorBubbling());
} }
public function testOverrideErrorBubbling() public function testOverrideErrorBubbling()
@ -554,7 +554,7 @@ class FormTypeTest extends TypeTestCase
'error_bubbling' => true, 'error_bubbling' => true,
)); ));
$this->assertTrue($form->getErrorBubbling()); $this->assertTrue($form->getConfig()->getErrorBubbling());
} }
public function testPropertyPath() public function testPropertyPath()

View File

@ -376,7 +376,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->form->add($child); $this->form->add($child);
$this->assertSame($this->form, $child->getParent()); $this->assertSame($this->form, $child->getParent());
$this->assertSame(array('foo' => $child), $this->form->getChildren()); $this->assertSame(array('foo' => $child), $this->form->all());
} }
/** /**
@ -440,7 +440,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->form->add($this->getBuilder('foo')->getForm()); $this->form->add($this->getBuilder('foo')->getForm());
$this->form->add($this->getBuilder('bar')->getForm()); $this->form->add($this->getBuilder('bar')->getForm());
$this->assertSame($this->form->getChildren(), iterator_to_array($this->form)); $this->assertSame($this->form->all(), iterator_to_array($this->form));
} }
public function testBound() public function testBound()
@ -1104,7 +1104,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type1::buildView'; $calls[] = 'type1::buildView';
$test->assertTrue($view->hasParent()); $test->assertTrue($view->hasParent());
$test->assertFalse($view->hasChildren()); $test->assertEquals(0, count($view));
})); }));
$type1Extension->expects($this->once()) $type1Extension->expects($this->once())
@ -1112,7 +1112,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type1ext::buildView'; $calls[] = 'type1ext::buildView';
$test->assertTrue($view->hasParent()); $test->assertTrue($view->hasParent());
$test->assertFalse($view->hasChildren()); $test->assertEquals(0, count($view));
})); }));
$type2->expects($this->once()) $type2->expects($this->once())
@ -1120,7 +1120,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type2::buildView'; $calls[] = 'type2::buildView';
$test->assertTrue($view->hasParent()); $test->assertTrue($view->hasParent());
$test->assertFalse($view->hasChildren()); $test->assertEquals(0, count($view));
})); }));
$type2Extension->expects($this->once()) $type2Extension->expects($this->once())
@ -1128,35 +1128,35 @@ class FormTest extends \PHPUnit_Framework_TestCase
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type2ext::buildView'; $calls[] = 'type2ext::buildView';
$test->assertTrue($view->hasParent()); $test->assertTrue($view->hasParent());
$test->assertFalse($view->hasChildren()); $test->assertEquals(0, count($view));
})); }));
$type1->expects($this->once()) $type1->expects($this->once())
->method('finishView') ->method('finishView')
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type1::finishView'; $calls[] = 'type1::finishView';
$test->assertTrue($view->hasChildren()); $test->assertGreaterThan(0, count($view));
})); }));
$type1Extension->expects($this->once()) $type1Extension->expects($this->once())
->method('finishView') ->method('finishView')
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type1ext::finishView'; $calls[] = 'type1ext::finishView';
$test->assertTrue($view->hasChildren()); $test->assertGreaterThan(0, count($view));
})); }));
$type2->expects($this->once()) $type2->expects($this->once())
->method('finishView') ->method('finishView')
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type2::finishView'; $calls[] = 'type2::finishView';
$test->assertTrue($view->hasChildren()); $test->assertGreaterThan(0, count($view));
})); }));
$type2Extension->expects($this->once()) $type2Extension->expects($this->once())
->method('finishView') ->method('finishView')
->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) {
$calls[] = 'type2ext::finishView'; $calls[] = 'type2ext::finishView';
$test->assertTrue($view->hasChildren()); $test->assertGreaterThan(0, count($view));
})); }));
$form = $this->getBuilder()->setTypes(array($type1, $type2))->getForm(); $form = $this->getBuilder()->setTypes(array($type1, $type2))->getForm();