Browse Source

[Form] Renamed field option 'disabled' to 'read_only'. How to render read-only fields is now the responsibility of the renderer

Bernhard Schussek 14 years ago
parent
commit
cb599f417e

+ 6 - 6
src/Symfony/Component/Form/Field.php

@@ -67,7 +67,7 @@ class Field implements FieldInterface
     private $transformationSuccessful = true;
     private $validator;
     private $renderer;
-    private $disabled = false;
+    private $readOnly = false;
     private $dispatcher;
     private $attributes;
 
@@ -75,7 +75,7 @@ class Field implements FieldInterface
         RendererInterface $renderer, DataTransformerInterface $clientTransformer = null,
         DataTransformerInterface $normTransformer = null,
         FieldValidatorInterface $validator = null, $required = false,
-        $disabled = false, array $attributes = array())
+        $readOnly = false, array $attributes = array())
     {
         $this->name = (string)$name;
         $this->dispatcher = $dispatcher;
@@ -84,7 +84,7 @@ class Field implements FieldInterface
         $this->normTransformer = $normTransformer;
         $this->validator = $validator;
         $this->required = $required;
-        $this->disabled = $disabled;
+        $this->readOnly = $readOnly;
         $this->attributes = $attributes;
 
         $renderer->setField($this);
@@ -122,10 +122,10 @@ class Field implements FieldInterface
     /**
      * {@inheritDoc}
      */
-    public function isDisabled()
+    public function isReadOnly()
     {
-        if (null === $this->parent || !$this->parent->isDisabled()) {
-            return $this->disabled;
+        if (null === $this->parent || !$this->parent->isReadOnly()) {
+            return $this->readOnly;
         }
 
         return true;

+ 6 - 6
src/Symfony/Component/Form/FieldBuilder.php

@@ -30,7 +30,7 @@ class FieldBuilder
 
     private $factory;
 
-    private $disabled;
+    private $readOnly;
 
     private $required;
 
@@ -110,16 +110,16 @@ class FieldBuilder
         return $this->data;
     }
 
-    public function setDisabled($disabled)
+    public function setReadOnly($readOnly)
     {
-        $this->disabled = $disabled;
+        $this->readOnly = $readOnly;
 
         return $this;
     }
 
-    public function getDisabled()
+    public function getReadOnly()
     {
-        return $this->disabled;
+        return $this->readOnly;
     }
 
     /**
@@ -288,7 +288,7 @@ class FieldBuilder
             $this->getNormTransformer(),
             $this->getValidator(),
             $this->getRequired(),
-            $this->getDisabled(),
+            $this->getReadOnly(),
             $this->getAttributes()
         );
 

+ 5 - 5
src/Symfony/Component/Form/FieldInterface.php

@@ -65,17 +65,17 @@ interface FieldInterface
     function isRequired();
 
     /**
-     * Returns whether this field is disabled
+     * Returns whether this field can be read only
      *
-     * The content of a disabled field is displayed, but not allowed to be
-     * modified. The validation of modified, disabled fields should fail.
+     * The content of a read-only field is displayed, but not allowed to be
+     * modified. The validation of modified read-only fields should fail.
      *
-     * Fields whose parents are disabled are considered disabled regardless of
+     * Fields whose parents are read-only are considered read-only regardless of
      * their own state.
      *
      * @return Boolean
      */
-    function isDisabled();
+    function isReadOnly();
 
     /**
      * Returns whether the field is empty

+ 2 - 2
src/Symfony/Component/Form/Form.php

@@ -65,7 +65,7 @@ class Form extends Field implements \IteratorAggregate, FormInterface
         RendererInterface $renderer, DataTransformerInterface $clientTransformer = null,
         DataTransformerInterface $normalizationTransformer = null,
         DataMapperInterface $dataMapper, FieldValidatorInterface $validator = null,
-        $required = false, $disabled = false, array $attributes = array())
+        $required = false, $readOnly = false, array $attributes = array())
     {
         $dispatcher->addListener(array(
             Events::postSetData,
@@ -76,7 +76,7 @@ class Form extends Field implements \IteratorAggregate, FormInterface
         $this->dataMapper = $dataMapper;
 
         parent::__construct($name, $dispatcher, $renderer, $clientTransformer,
-            $normalizationTransformer, $validator, $required, $disabled,
+            $normalizationTransformer, $validator, $required, $readOnly,
             $attributes);
     }
 

+ 1 - 1
src/Symfony/Component/Form/FormBuilder.php

@@ -251,7 +251,7 @@ class FormBuilder extends FieldBuilder
             $this->getDataMapper(),
             $this->getValidator(),
             $this->getRequired(),
-            $this->getDisabled(),
+            $this->getReadOnly(),
             $this->getAttributes()
         );
 

+ 1 - 1
src/Symfony/Component/Form/Renderer/Plugin/FieldPlugin.php

@@ -45,7 +45,7 @@ class FieldPlugin implements RendererPluginInterface
         $renderer->setVar('name', $name);
         $renderer->setVar('errors', $field->getErrors());
         $renderer->setVar('value', $field->getClientData());
-        $renderer->setVar('disabled', $field->isDisabled());
+        $renderer->setVar('disabled', $field->isReadOnly());
         $renderer->setVar('required', $field->isRequired());
         $renderer->setVar('class', null);
         $renderer->setVar('max_length', null);

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

@@ -52,7 +52,7 @@ class FieldType extends AbstractType
             : (array)$options['validation_groups'];
 
         $builder->setRequired($options['required'])
-            ->setDisabled($options['disabled'])
+            ->setReadOnly($options['read_only'])
             ->setAttribute('by_reference', $options['by_reference'])
             ->setAttribute('property_path', $options['property_path'])
             ->setAttribute('validation_groups', $options['validation_groups'])
@@ -73,7 +73,7 @@ class FieldType extends AbstractType
             'data' => null,
             'trim' => true,
             'required' => true,
-            'disabled' => false,
+            'read_only' => false,
             'max_length' => null,
             'property_path' => false,
             'by_reference' => true,

+ 10 - 10
tests/Symfony/Tests/Component/Form/FieldTest.php

@@ -77,23 +77,23 @@ class FieldTest extends TestCase
         $this->assertTrue($field->isRequired());
     }
 
-    public function testPassDisabledAsOption()
+    public function testPassReadOnlyAsOption()
     {
-        $field = $this->factory->create('field', 'title', array('disabled' => false));
+        $field = $this->factory->create('field', 'title', array('read_only' => false));
 
-        $this->assertFalse($field->isDisabled());
+        $this->assertFalse($field->isReadOnly());
 
-        $field = $this->factory->create('field', 'title', array('disabled' => true));
+        $field = $this->factory->create('field', 'title', array('read_only' => true));
 
-        $this->assertTrue($field->isDisabled());
+        $this->assertTrue($field->isReadOnly());
     }
 
-    public function testFieldIsDisabledIfParentIsDisabled()
+    public function testFieldIsReadOnlyIfParentIsReadOnly()
     {
-        $field = $this->factory->create('field', 'title', array('disabled' => false));
-        $field->setParent($this->factory->create('field', 'title', array('disabled' => true)));
+        $field = $this->factory->create('field', 'title', array('read_only' => false));
+        $field->setParent($this->factory->create('field', 'title', array('read_only' => true)));
 
-        $this->assertTrue($field->isDisabled());
+        $this->assertTrue($field->isReadOnly());
     }
 
     public function testFieldWithNoErrorsIsValid()
@@ -302,7 +302,7 @@ class FieldTest extends TestCase
         $this->assertEquals('reverse[a]', $field->getData());
     }
 
-    public function testBoundDataIsNotTrimmedBeforeTransformingIfDisabled()
+    public function testBoundDataIsNotTrimmedBeforeTransformingIfReadOnly()
     {
         $clientTransformer = new FixedDataTransformer(array(
             null => '',