Skip to content

Commit 9c70594

Browse files
author
Eugene Tupikov
committed
#33 improved code
1 parent 6f75ac9 commit 9c70594

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/components/BaseColumn.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ public function renderInput($name, $options)
231231
{
232232
$options = array_merge($this->options, $options);
233233
$method = 'render' . Inflector::camelize($this->type);
234-
235234
$value = $this->prepareValue();
235+
236+
if (isset($options['items'])) {
237+
$options['items'] = $this->prepareItems($options['items']);
238+
}
239+
236240
if (method_exists($this, $method)) {
237241
$input = call_user_func_array([$this, $method], [$name, $value, $options]);
238242
} else {
@@ -253,20 +257,21 @@ public function renderInput($name, $options)
253257
protected function renderDropDownList($name, $value, $options)
254258
{
255259
Html::addCssClass($options, 'form-control');
256-
return Html::dropDownList($name, $value, $this->prepareItems(), $options);
260+
return Html::dropDownList($name, $value, $this->prepareItems($this->items), $options);
257261
}
258262

259263
/**
260264
* Returns the items for list.
261265
*
266+
* @param mixed $items
262267
* @return array|Closure|mixed
263268
*/
264-
private function prepareItems()
269+
private function prepareItems($items)
265270
{
266-
if ($this->items instanceof \Closure) {
267-
return call_user_func($this->items, $this->getModel());
271+
if ($items instanceof \Closure) {
272+
return call_user_func($items, $this->getModel());
268273
} else {
269-
return $this->items;
274+
return $items;
270275
}
271276
}
272277

@@ -279,7 +284,7 @@ private function prepareItems()
279284
protected function renderListBox($name, $value, $options)
280285
{
281286
Html::addCssClass($options, 'form-control');
282-
return Html::listBox($name, $value, $this->prepareItems(), $options);
287+
return Html::listBox($name, $value, $this->prepareItems($this->items), $options);
283288
}
284289

285290
/**
@@ -325,7 +330,7 @@ protected function renderRadioList($name, $value, $options)
325330
$options['item'] = function ($index, $label, $name, $checked, $value) {
326331
return '<div class="radio">' . Html::radio($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
327332
};
328-
$input = Html::radioList($name, $value, $this->prepareItems(), $options);
333+
$input = Html::radioList($name, $value, $this->prepareItems($this->items), $options);
329334
return Html::tag('div', $input, ['class' => 'radio-list']);
330335
}
331336

@@ -361,7 +366,7 @@ protected function renderCheckboxList($name, $value, $options)
361366
$options['item'] = function ($index, $label, $name, $checked, $value) {
362367
return '<div class="checkbox">' . Html::checkbox($name, $checked, ['label' => $label, 'value' => $value]) . '</div>';
363368
};
364-
$input = Html::checkboxList($name, $value, $this->prepareItems(), $options);
369+
$input = Html::checkboxList($name, $value, $this->prepareItems($this->items), $options);
365370
return Html::tag('div', $input, ['class' => 'checkbox-list']);
366371
}
367372

0 commit comments

Comments
 (0)