administrcms/form

View on GitHub
src/Field/RadioGroup.php

Summary

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

namespace Administr\Form\Field;

class RadioGroup extends Field
{
    protected $radios = [];

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

    public function radio($label, array $options = [])
    {
        $this->radios[] = (new Radio($this->getName(), $label, $options))->setValue($this->getValue());
        return $this;
    }

    public function setValue($value)
    {
        foreach($this->radios as $radio) {
            $radio->setValue($value);
        }

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