You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB
PHP

<?php
namespace Artmark\Forms\Fields;
use Artmark\Forms\AbstractChoiceField;
use Artmark\Forms\AbstractChoiceOption;
/**
* Description of RadioField
*
* @author Andrey Pokidov <andrey.pokidov@gmail.com>
*/
class RadioField extends AbstractChoiceField
{
public function __construct($form, $name)
{
parent::__construct($form, 'radio', $name);
}
/**
* Создаёт новый экземпляр опции
* @return RadioOption
*/
protected function createOption($value, $text)
{
return new RadioOption($this, $value, $text);
}
public function appendAttributesToOption(AbstractChoiceOption $option, array & $attributes)
{
if ($this->isSelected($option)) {
$attributes['checked'] = null;
}
if (!$option->hasCssClasses()) {
$this->appendCssClassAttribute($attributes);
}
if (!$option->hasStyle()) {
$this->appendStyleAttribute($attributes);
}
if ($this->isDisabled()) {
$this->appendDisabledAttribute($attributes);
}
$attributes['name'] = $this->name();
if (!$option->hasId()) {
$option->setId($this->name() . '_' . $option->value());
$attributes['id'] = $option->id();
}
}
}