@@ -231,8 +231,12 @@ public function renderInput($name, $options)
231
231
{
232
232
$ options = array_merge ($ this ->options , $ options );
233
233
$ method = 'render ' . Inflector::camelize ($ this ->type );
234
-
235
234
$ value = $ this ->prepareValue ();
235
+
236
+ if (isset ($ options ['items ' ])) {
237
+ $ options ['items ' ] = $ this ->prepareItems ($ options ['items ' ]);
238
+ }
239
+
236
240
if (method_exists ($ this , $ method )) {
237
241
$ input = call_user_func_array ([$ this , $ method ], [$ name , $ value , $ options ]);
238
242
} else {
@@ -253,20 +257,21 @@ public function renderInput($name, $options)
253
257
protected function renderDropDownList ($ name , $ value , $ options )
254
258
{
255
259
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 );
257
261
}
258
262
259
263
/**
260
264
* Returns the items for list.
261
265
*
266
+ * @param mixed $items
262
267
* @return array|Closure|mixed
263
268
*/
264
- private function prepareItems ()
269
+ private function prepareItems ($ items )
265
270
{
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 ());
268
273
} else {
269
- return $ this -> items ;
274
+ return $ items ;
270
275
}
271
276
}
272
277
@@ -279,7 +284,7 @@ private function prepareItems()
279
284
protected function renderListBox ($ name , $ value , $ options )
280
285
{
281
286
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 );
283
288
}
284
289
285
290
/**
@@ -325,7 +330,7 @@ protected function renderRadioList($name, $value, $options)
325
330
$ options ['item ' ] = function ($ index , $ label , $ name , $ checked , $ value ) {
326
331
return '<div class="radio"> ' . Html::radio ($ name , $ checked , ['label ' => $ label , 'value ' => $ value ]) . '</div> ' ;
327
332
};
328
- $ input = Html::radioList ($ name , $ value , $ this ->prepareItems (), $ options );
333
+ $ input = Html::radioList ($ name , $ value , $ this ->prepareItems ($ this -> items ), $ options );
329
334
return Html::tag ('div ' , $ input , ['class ' => 'radio-list ' ]);
330
335
}
331
336
@@ -361,7 +366,7 @@ protected function renderCheckboxList($name, $value, $options)
361
366
$ options ['item ' ] = function ($ index , $ label , $ name , $ checked , $ value ) {
362
367
return '<div class="checkbox"> ' . Html::checkbox ($ name , $ checked , ['label ' => $ label , 'value ' => $ value ]) . '</div> ' ;
363
368
};
364
- $ input = Html::checkboxList ($ name , $ value , $ this ->prepareItems (), $ options );
369
+ $ input = Html::checkboxList ($ name , $ value , $ this ->prepareItems ($ this -> items ), $ options );
365
370
return Html::tag ('div ' , $ input , ['class ' => 'checkbox-list ' ]);
366
371
}
367
372
0 commit comments