Skip to content
Permalink
Browse files

Update based on review comments.

  • Loading branch information...
markstory committed Jan 8, 2014
1 parent 78d7bbb commit 9a8f6dbf67058d42ae3aeb67455196896b965266
Showing with 25 additions and 23 deletions.
  1. +25 −23 Cake/View/Input/SelectBox.php
@@ -101,8 +101,7 @@ protected function _renderContent($data) {
if (!empty($data['empty'])) {
$value = $data['empty'] === true ? '' : $data['empty'];
$empty = ['' => $value];
$options = $empty + $options;
$options = ['' => $value] + $options;
}
if (empty($options)) {
return $out;
@@ -130,34 +129,37 @@ protected function _renderContent($data) {
protected function _renderOptions($options, $disabled, $selected, $escape) {
$out = [];
foreach ($options as $key => $val) {
// Option groups
if (!is_int($key) && is_array($val) || $val instanceof Traversable) {
$groupOptions = $this->_renderOptions($val, $disabled, $selected, $escape);
$out[] = $this->_templates->format('optgroup', [
'label' => $escape ? h($key) : $key,
'content' => implode('', $groupOptions)
]);
} else {
$optAttrs = [
'name' => $key,
'value' => $val,
];
if (is_array($val) && isset($optAttrs['name'], $optAttrs['value'])) {
$optAttrs = $val;
}
if ($this->_isSelected($key, $selected)) {
$optAttrs['selected'] = true;
}
if ($this->_isDisabled($key, $disabled)) {
$optAttrs['disabled'] = true;
}
$optAttrs['escape'] = $escape;
$out[] = $this->_templates->format('option', [
'name' => $escape ? h($optAttrs['name']) : $optAttrs['name'],
'value' => $escape ? h($optAttrs['value']) : $optAttrs['value'],
'attrs' => $this->_templates->formatAttributes($optAttrs, ['name', 'value']),
]);
continue;
}
// Basic options
$optAttrs = [
'name' => $key,
'value' => $val,
];
if (is_array($val) && isset($optAttrs['name'], $optAttrs['value'])) {
$optAttrs = $val;
}
if ($this->_isSelected($key, $selected)) {
$optAttrs['selected'] = true;
}
if ($this->_isDisabled($key, $disabled)) {
$optAttrs['disabled'] = true;
}
$optAttrs['escape'] = $escape;
$out[] = $this->_templates->format('option', [
'name' => $escape ? h($optAttrs['name']) : $optAttrs['name'],
'value' => $escape ? h($optAttrs['value']) : $optAttrs['value'],
'attrs' => $this->_templates->formatAttributes($optAttrs, ['name', 'value']),
]);
}
return $out;
}

0 comments on commit 9a8f6db

Please sign in to comment.
You can’t perform that action at this time.