Browse Source

Renamed attributes to attr to be consistent with templating.

Miha Vrhovnik 14 năm trước cách đây
mục cha
commit
e8326aa650

+ 5 - 5
src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

@@ -35,8 +35,8 @@ class FieldType extends AbstractType
         } else {
             $options['property_path'] = new PropertyPath($options['property_path']);
         }
-        if (!is_array($options['attributes'])) {
-            throw new FormException('attributes option should be array');
+        if (!is_array($options['attr'])) {
+            throw new FormException('The "attr" option must be "array".');
         }
         
         $builder
@@ -50,7 +50,7 @@ class FieldType extends AbstractType
             ->setAttribute('max_length', $options['max_length'])
             ->setAttribute('pattern', $options['pattern'])
             ->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
-            ->setAttribute('attributes', $options['attributes'] ?: array())
+            ->setAttribute('attr', $options['attr'] ?: array())
             ->setData($options['data'])
             ->addValidator(new DefaultValidator())
         ;
@@ -93,7 +93,7 @@ class FieldType extends AbstractType
             ->set('size', null)
             ->set('label', $form->getAttribute('label'))
             ->set('multipart', false)
-            ->set('attr', $form->getAttribute('attributes'))
+            ->set('attr', $form->getAttribute('attr'))
             ->set('types', $types)
         ;
     }
@@ -113,7 +113,7 @@ class FieldType extends AbstractType
             'error_bubbling'    => false,
             'error_mapping'     => array(),
             'label'             => null,
-            'attributes'        => array(),
+            'attr'              => array(),
         );
 
         $class = isset($options['data_class']) ? $options['data_class'] : null;

+ 3 - 3
tests/Symfony/Tests/Component/Form/Extension/Core/Type/FieldTypeTest.php

@@ -198,9 +198,9 @@ class FieldTypeTest extends TypeTestCase
     
     public function testGetAttributesIsEmpty()
     {
-        $form = $this->factory->create('field', null, array('attributes' => array()));
+        $form = $this->factory->create('field', null, array('attr' => array()));
 
-        $this->assertEquals(0, count($form->getAttribute('attributes')));
+        $this->assertEquals(0, count($form->getAttribute('attr')));
     }
 
     /**
@@ -208,7 +208,7 @@ class FieldTypeTest extends TypeTestCase
      */
     public function testAttributesException()
     {
-        $form = $this->factory->create('field', null, array('attributes' => ''));
+        $form = $this->factory->create('field', null, array('attr' => ''));
     }
 
 }