1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?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);
- }
- }
|