Example #1
0
 public function bind($taintedData)
 {
     if (is_null($taintedData)) {
         $taintedData = array();
     }
     foreach ($this as $name => $field) {
         if (!isset($taintedData[$name]) && $this->getOption('modifiable') && $name != '$$key$$') {
             $this->remove($name);
         }
     }
     foreach ($taintedData as $name => $value) {
         if (!isset($this[$name]) && $this->getOption('modifiable')) {
             $this->add($this->newField($name, $name));
         }
     }
     return parent::bind($taintedData);
 }
Example #2
0
 public function testSetGenerator_calledAfterAdding()
 {
     $generator = $this->getMock('Symfony\\Components\\Form\\HtmlGeneratorInterface');
     $field = $this->createMockField('firstName');
     $field->expects($this->exactly(2))->method('setGenerator');
     $group = new FieldGroup('author');
     $group->add($field);
     $group->setGenerator($generator);
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 protected function reverseTransform($value)
 {
     return parent::reverseTransform(array_merge($value['date'], $value['time']));
 }
Example #4
0
 /**
  * Binds the form with the given data.
  *
  * @param  array $taintedData  The data to bind to the form
  * @return boolean             Whether the form is valid
  */
 protected function doBind(array $taintedData)
 {
     parent::bind($taintedData);
 }
Example #5
0
 /**
  * Merges a field group into this group. The group must have a unique name
  * within the group. Otherwise the existing field is overwritten.
  *
  * Contrary to added groups, merged groups operate on the same object as
  * the group they are merged into.
  *
  * <code>
  * class Entity
  * {
  *   public $longitude;
  *   public $latitude;
  * }
  *
  * $entity = new Entity();
  *
  * $form = new Form('entity', $entity, $validator);
  *
  * $locationGroup = new FieldGroup('location');
  * $locationGroup->add(new TextField('longitude'));
  * $locationGroup->add(new TextField('latitude'));
  *
  * $form->merge($locationGroup);
  * </code>
  *
  * @param FieldGroup $group
  */
 public function merge(FieldGroup $group)
 {
     if ($group->isBound()) {
         throw new AlreadyBoundException('A bound form group cannot be merged');
     }
     foreach ($group as $field) {
         $group->remove($field->getKey());
         $this->add($field);
         if (($path = $group->getPropertyPath()) !== null) {
             $field->setPropertyPath($path . '.' . $field->getPropertyPath());
         }
     }
     return $this;
 }