Selaa lähdekoodia

[Form] Changed the default value of the 'property_path' option to NULL. Explicitely set it to '' or false to disable mapping for a field/form

Bernhard Schussek 14 vuotta sitten
vanhempi
commit
dc38eeffe3

+ 1 - 1
src/Symfony/Component/Form/Type/CollectionType.php

@@ -20,7 +20,7 @@ class CollectionType extends AbstractType
     {
         if ($options['modifiable'] && $options['prototype']) {
             $builder->add('$$name$$', $options['type'], array(
-                'property_path' => null,
+                'property_path' => false,
                 'required' => false,
             ));
         }

+ 1 - 1
src/Symfony/Component/Form/Type/CsrfType.php

@@ -48,7 +48,7 @@ class CsrfType extends AbstractType
         return array(
             'csrf_provider' => $this->csrfProvider,
             'page_id' => null,
-            'property_path' => null,
+            'property_path' => false,
         );
     }
 

+ 3 - 3
src/Symfony/Component/Form/Type/FieldType.php

@@ -35,11 +35,11 @@ class FieldType extends AbstractType
 
     public function buildForm(FormBuilder $builder, array $options)
     {
-        if (false === $options['property_path']) {
+        if (null === $options['property_path']) {
             $options['property_path'] = $builder->getName();
         }
 
-        if (null === $options['property_path'] || '' === $options['property_path']) {
+        if (false === $options['property_path'] || '' === $options['property_path']) {
             $options['property_path'] = null;
         } else {
             $options['property_path'] = new PropertyPath($options['property_path']);
@@ -101,7 +101,7 @@ class FieldType extends AbstractType
             'required' => true,
             'read_only' => false,
             'max_length' => null,
-            'property_path' => false,
+            'property_path' => null,
             'by_reference' => true,
             'validation_groups' => true,
             'error_bubbling' => false,

+ 8 - 1
tests/Symfony/Tests/Component/Form/Type/FieldTypeTest.php

@@ -57,11 +57,18 @@ class FieldTypeTest extends TestCase
         $this->assertEquals(null, $form->getAttribute('property_path'));
     }
 
+    public function testGetPropertyPath_pathIsFalse()
+    {
+        $form = $this->factory->create('field', 'title', array('property_path' => false));
+
+        $this->assertEquals(null, $form->getAttribute('property_path'));
+    }
+
     public function testGetPropertyPath_pathIsNull()
     {
         $form = $this->factory->create('field', 'title', array('property_path' => null));
 
-        $this->assertEquals(null, $form->getAttribute('property_path'));
+        $this->assertEquals(new PropertyPath('title'), $form->getAttribute('property_path'));
     }
 
     public function testPassRequiredAsOption()