remove() public method

Removes the field with the given key.
public remove ( string $key )
$key string
コード例 #1
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;
 }
コード例 #2
0
ファイル: FieldGroupTest.php プロジェクト: netixpro/symfony
 public function testRemoveUnsetsFieldParent()
 {
     $group = new FieldGroup('author');
     $field = $this->createMockField('firstName');
     $field->expects($this->exactly(2))->method('setParent');
     // PHPUnit fails to compare subsequent method calls with different arguments
     $group->add($field);
     $group->remove('firstName');
 }