/**
* 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;
}