Symfony\Component\Form\FieldGroup::merge PHP Метод

merge() публичный Метод

Contrary to added groups, merged groups operate on the same object as the group they are merged into. 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);
public merge ( FieldGroup $group )
$group FieldGroup
    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;
    }

Usage Example

Пример #1
0
 public function testMergeThrowsExceptionIfOtherGroupAlreadyBound()
 {
     $group1 = new FieldGroup('author');
     $group2 = new FieldGroup('publisher');
     $group2->add($this->createMockField('firstName'));
     $group2->bind(array('firstName' => 'Bernhard'));
     $this->setExpectedException('Symfony\\Component\\Form\\Exception\\AlreadyBoundException');
     $group1->merge($group2);
 }