administrcms/form

View on GitHub
src/Field/CheckboxGroup.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%
<?php

namespace Administr\Form\Field;

class CheckboxGroup extends Field
{
    protected $checkboxes = [];

    public function checkboxes()
    {
        return $this->checkboxes;
    }

    public function checkbox($label, array $attributes = [])
    {
        $this->checkboxes[] = (new Checkbox($this->getName(), $label, $attributes))->setValue($this->getValue());

        return $this;
    }

    public function setValue($value)
    {
        foreach($this->checkboxes as $checkbox) {
            $checkbox->setValue($value);
        }

        return parent::setValue($value);
    }
}