public static function radioList($name, $selection = null, $items = [], $options = [])
{
$formatter = ArrayHelper::remove($options, 'item');
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
$encode = ArrayHelper::remove($options, 'encode', true);
$separator = ArrayHelper::remove($options, 'separator', "\n");
$tag = ArrayHelper::remove($options, 'tag', 'div');
// add a hidden field so that if the list box has no option being selected, it still submits a value
$hidden = isset($options['unselect']) ? static::hiddenInput($name, $options['unselect']) : '';
unset($options['unselect']);
$lines = [];
$index = 0;
foreach ($items as $value => $label) {
$checked = $selection !== null && (!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection) || ArrayHelper::isTraversable($selection) && ArrayHelper::isIn($value, $selection));
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$lines[] = static::radio($name, $checked, array_merge($itemOptions, ['value' => $value, 'label' => $encode ? static::encode($label) : $label]));
}
$index++;
}
$visibleContent = implode($separator, $lines);
if ($tag === false) {
return $hidden . $visibleContent;
}
return $hidden . static::tag($tag, $visibleContent, $options);
}