public function addElement(Element $element) { $name = $element->getName(); if (isset($this->elements[$name])) { throw new InvalidArgumentException("Duplicate element exists with [{$name}]"); } $element->setFieldset($this); $this->elements[$name] = $element; return $this; }
public function testElementName() { $e = new Element('name', 'text', array()); $e->setLabel('First Name'); //stand-alone $this->assertEquals('name', $e->getName()); //under fieldset $fs = m::mock('SH\\Formy\\Fieldset')->shouldReceive('getName')->times(1)->andReturn('customers')->getMock(); $e->setFieldset($fs); $this->assertEquals('customers[name]', $e->getName()); }
/** * Make child element with base element spec * @param mixed $value value for the element * @return Element */ public function makeElement($value) { $element = new Element("{$this->name}[]", $this->type, $this->attributes); $element->setValue($value); if ($this->meta) { $element->setMetas($this->meta); } if ($this->fieldset) { $element->setFieldset($this->fieldset); } return $element; }