123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace yii\grid;
- use Closure;
- use yii\base\InvalidConfigException;
- use yii\helpers\Html;
- class RadioButtonColumn extends Column
- {
-
- public $name = 'radioButtonSelection';
-
- public $radioOptions = [];
-
- public function init()
- {
- parent::init();
- if (empty($this->name)) {
- throw new InvalidConfigException('The "name" property must be set.');
- }
- }
-
- protected function renderDataCellContent($model, $key, $index)
- {
- if ($this->content !== null) {
- return parent::renderDataCellContent($model, $key, $index);
- }
- if ($this->radioOptions instanceof Closure) {
- $options = call_user_func($this->radioOptions, $model, $key, $index, $this);
- } else {
- $options = $this->radioOptions;
- if (!isset($options['value'])) {
- $options['value'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $key;
- }
- }
- $checked = isset($options['checked']) ? $options['checked'] : false;
- return Html::radio($this->name, $checked, $options);
- }
- }
|