Symfony\Component\Form\FieldGroup::add PHP Method

add() public method

If you add a nested group, this group should also be represented in the object hierarchy. If you want to add a group that operates on the same hierarchy level, use merge(). class Entity { public $location; } class Location { public $longitude; public $latitude; } $entity = new Entity(); $entity->location = new Location(); $form = new Form('entity', $entity, $validator); $locationGroup = new FieldGroup('location'); $locationGroup->add(new TextField('longitude')); $locationGroup->add(new TextField('latitude')); $form->add($locationGroup);
public add ( Symfony\Component\Form\FieldInterface $field )
$field Symfony\Component\Form\FieldInterface
    public function add(FieldInterface $field)
    {
        if ($this->isBound()) {
            throw new AlreadyBoundException('You cannot add fields after binding a form');
        }

        $this->fields[$field->getKey()] = $field;

        $field->setParent($this);
        $field->setLocale($this->locale);

        $data = $this->getTransformedData();

        // if the property "data" is NULL, getTransformedData() returns an empty
        // string
        if (!empty($data) && $field->getPropertyPath() !== null) {
            $field->updateFromObject($data);
        }

        return $field;
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  *
  * @throws FormException  When the field is in mode HybridField::FIELD adding
  *                        subfields is not allowed
  */
 public function add($field)
 {
     if ($this->mode === self::FIELD) {
         throw new FormException('You cannot add nested fields while in mode FIELD');
     }
     return parent::add($field);
 }
All Usage Examples Of Symfony\Component\Form\FieldGroup::add