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

add() public method

public add ( $child, $type = null, array $options = [] )
$options array
    public function add($child, $type = null, array $options = array())
    {
        if ($this->locked) {
            throw new FormException('The form builder cannot be modified anymore.');
        }

        if ($child instanceof self) {
            $child->setParent($this);
            $this->children[$child->getName()] = $child;

            // In case an unresolved child with the same name exists
            unset($this->unresolvedChildren[$child->getName()]);

            return $this;
        }

        if (!is_string($child)) {
            throw new UnexpectedTypeException($child, 'string or Symfony\Component\Form\FormBuilder');
        }

        if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {
            throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\FormTypeInterface');
        }

        // Add to "children" to maintain order
        $this->children[$child] = null;
        $this->unresolvedChildren[$child] = array(
            'type'    => $type,
            'options' => $options,
        );

        return $this;
    }

Usage Example

Esempio n. 1
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->add('product');
     $builder->add('price');
     $builder->add('start_date');
     $builder->add('expire_date');
 }
All Usage Examples Of Symfony\Component\Form\FormBuilder::add