Example #1
0
 public function testIsBound()
 {
     $group = new FieldGroup('author');
     $this->assertFalse($group->isBound());
     $group->bind(array('firstName' => 'Bernhard'));
     $this->assertTrue($group->isBound());
 }
Example #2
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;
 }