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.

53 lines
1.2 KiB
PHP

<?php
namespace Artmark\Forms\Fields;
use Artmark\Forms\AbstractChoiceField;
use Artmark\Forms\AbstractChoiceOption;
use Artmark\Forms\Attributes\SizeAttribute;
/**
* Description of TextField
*
* @author Andrey Pokidov <andrey.pokidov@gmail.com>
*/
class SelectField extends AbstractChoiceField
{
use SizeAttribute;
public function __construct($form, $name)
{
parent::__construct($form, 'select', $name);
}
public function getAssociativeAttributes()
{
$attributes = parent::getAssociativeAttributes();
$this->appendSizeAttribute($attributes);
if ($this->isMultiSelect()) {
$attributes['multiple'] = null;
}
return $attributes;
}
/**
* Создаёт новый экземпляр опции
* @return SelectOption
*/
protected function createOption($value, $text)
{
return new SelectOption($this, $value, $text);
}
public function appendAttributesToOption(AbstractChoiceOption $option, array & $attributes)
{
if ($this->isSelected($option)) {
$attributes['selected'] = null;
}
}
}