Browse Source

Merge remote branch 'vicb/form-fluid'

* vicb/form-fluid:
  [Form] Fix the Form fluid interface
  [Form] Fix the fluid interface of FormBuilder
  [Form] Fix the fluid interface of FormBuilder
Fabien Potencier 14 years ago
parent
commit
75f0ab5d40
2 changed files with 31 additions and 4 deletions
  1. 20 4
      src/Symfony/Component/Form/Form.php
  2. 11 0
      src/Symfony/Component/Form/FormBuilder.php

+ 20 - 4
src/Symfony/Component/Form/Form.php

@@ -459,7 +459,7 @@ class Form implements \IteratorAggregate, FormInterface
     public function bind($clientData)
     {
         if ($this->readOnly) {
-            return;
+            return $this;
         }
 
         if (is_scalar($clientData) || null === $clientData) {
@@ -558,6 +558,8 @@ class Form implements \IteratorAggregate, FormInterface
         foreach ($this->validators as $validator) {
             $validator->validate($this);
         }
+
+        return $this;
     }
 
     /**
@@ -568,6 +570,8 @@ class Form implements \IteratorAggregate, FormInterface
      *
      * @param Request $request    The request to bind to the form
      *
+     * @return Form This form
+     *
      * @throws FormException if the method of the request is not one of GET, POST or PUT
      */
     public function bindRequest(Request $request)
@@ -588,7 +592,7 @@ class Form implements \IteratorAggregate, FormInterface
                 throw new FormException(sprintf('The request method "%s" is not supported', $request->getMethod()));
         }
 
-        $this->bind($data);
+        return $this->bind($data);
     }
 
     /**
@@ -604,9 +608,11 @@ class Form implements \IteratorAggregate, FormInterface
     }
 
     /**
-     * Adds an error to the field.
+     * Adds an error to this form.
+     *
+     * @param FormError $error
      *
-     * @see FormInterface
+     * @return Form The current form
      */
     public function addError(FormError $error)
     {
@@ -615,6 +621,8 @@ class Form implements \IteratorAggregate, FormInterface
         } else {
             $this->errors[] = $error;
         }
+
+        return $this;
     }
 
     /**
@@ -754,6 +762,8 @@ class Form implements \IteratorAggregate, FormInterface
      * Adds a child to the form.
      *
      * @param FormInterface $child The FormInterface to add as a child
+     *
+     * @return Form the current form
      */
     public function add(FormInterface $child)
     {
@@ -764,12 +774,16 @@ class Form implements \IteratorAggregate, FormInterface
         if ($this->dataMapper) {
             $this->dataMapper->mapDataToForm($this->getClientData(), $child);
         }
+
+        return $this;
     }
 
     /**
      * Removes a child from the form.
      *
      * @param string $name The name of the child to remove
+     *
+     * @return Form the current form
      */
     public function remove($name)
     {
@@ -778,6 +792,8 @@ class Form implements \IteratorAggregate, FormInterface
 
             unset($this->children[$name]);
         }
+
+        return $this;
     }
 
     /**

+ 11 - 0
src/Symfony/Component/Form/FormBuilder.php

@@ -372,9 +372,16 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Clears the client transformers.
+     *
+     * @return FormBuilder The current builder
+     */
     public function resetClientTransformers()
     {
         $this->clientTransformers = array();
+
+        return $this;
     }
 
     /**
@@ -610,12 +617,16 @@ class FormBuilder
      * Removes the field with the given name.
      *
      * @param string $name
+     *
+     * @return FormBuilder The current builder
      */
     public function remove($name)
     {
         if (isset($this->children[$name])) {
             unset($this->children[$name]);
         }
+
+        return $this;
     }
 
     /**