setData() public method

Initializes the field group with an object to operate on
See also: FieldInterface
public setData ( $data )
Example #1
0
 /**
  * {@inheritDoc}
  */
 public function setData($data)
 {
     if ($this->mode === self::GROUP) {
         parent::setData($data);
     } else {
         Field::setData($data);
     }
 }
 public function setData($collection)
 {
     if (!is_array($collection) && !$collection instanceof \Traversable) {
         throw new UnexpectedTypeException('The data must be an array');
     }
     foreach ($collection as $name => $value) {
         $this->add($this->newField($name, $name));
     }
     parent::setData($collection);
 }
Example #3
0
 public function setData($collection)
 {
     if (!is_array($collection) && !$collection instanceof \Traversable) {
         throw new UnexpectedTypeException('The data passed to the CollectionField must be an array or a Traversable');
     }
     foreach ($this as $name => $field) {
         if (!$this->getOption('modifiable') || '$$key$$' != $name) {
             $this->remove($name);
         }
     }
     foreach ($collection as $name => $value) {
         $this->add($this->newField($name, $name));
     }
     parent::setData($collection);
 }
Example #4
0
 public function testGetDataReturnsObject()
 {
     $group = new FieldGroup('author');
     $object = new \stdClass();
     $group->setData($object);
     $this->assertEquals($object, $group->getData());
 }