/** * Constructor * * Instantiate the set of checkbox input form elements * * @param string $name * @param array $values * @param string $indent * @param string|array $marked * @return CheckboxSet */ public function __construct($name, array $values, $indent = null, $marked = null) { if (null !== $marked) { if (!is_array($marked)) { $marked = [$marked]; } } else { $marked = []; } parent::__construct('fieldset', null, null, false, $indent); $this->attributes['class'] = 'checkbox-fieldset'; $this->setMarked($marked); $this->setName($name . '[]'); // Create the checkbox elements and related span elements. $i = null; foreach ($values as $k => $v) { $checkbox = new Input\Checkbox($name . '[]', null, $indent); $checkbox->setAttributes(['class' => 'checkbox', 'id' => $name . $i, 'value' => $k]); // Determine if the current radio element is checked. if (in_array($k, $this->marked)) { $checkbox->setAttribute('checked', 'checked'); } $span = new Child('span', null, null, false, $indent); $span->setAttribute('class', 'checkbox-span'); $span->setNodeValue($v); $this->addChildren([$checkbox, $span]); $this->checkboxes[] = $checkbox; $i++; } $this->value = $values; }
/** * Constructor * * Instantiate the radio input form elements * * @param string $name * @param array $values * @param string $indent * @param string $marked * @return RadioSet */ public function __construct($name, array $values, $indent = null, $marked = null) { parent::__construct('fieldset', null, null, false, $indent); $this->attributes['class'] = 'radio-fieldset'; $this->setMarked($marked); $this->setName($name); // Create the radio elements and related span elements. $i = null; foreach ($values as $k => $v) { $radio = new Input\Radio($name, null, $indent); $radio->setAttributes(['class' => 'radio', 'id' => $name . $i, 'value' => $k]); // Determine if the current radio element is checked. if (null !== $this->marked && $k == $this->marked) { $radio->setAttribute('checked', 'checked'); } $span = new Child('span', null, null, false, $indent); $span->setAttribute('class', 'radio-span'); $span->setNodeValue($v); $this->addChildren([$radio, $span]); $this->radios[] = $radio; $i++; } $this->value = $values; }
/** * Set attributes for the child element object * * @param array $a * @return Select */ public function setAttributes(array $a) { parent::setAttributes($a); $this->isMultiple(); return $this; }
/** * Insert a form element before another element * * @param string $name * @param Element\AbstractElement $e * @throws Exception * @return Form */ public function insertElementBefore($name, Element\AbstractElement $e) { $i = $this->getElementIndex($name); if (null === $i) { throw new Exception('Error: That element does not exist.'); } // If the element is the top of element of a group, switch out for the new element being inserted before foreach ($this->groups as $key => $group) { if ($group == $name) { $this->groups[$key] = $e->getName(); } } $this->childNodes = array_merge(array_slice($this->childNodes, 0, $i), [$e], array_slice($this->childNodes, $i)); return $this; }