Skip to content

Commit

Permalink
__selectOptions function
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcode authored and markstory committed Oct 30, 2010
1 parent d3c1e8c commit 6d97aed
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1479,10 +1479,9 @@ public function select($fieldName, $options = array(), $attributes = array()) {


$select = array_merge($select, $this->__selectOptions( $select = array_merge($select, $this->__selectOptions(
array_reverse($options, true), array_reverse($options, true),
$attributes['value'],
array(), array(),
$showParents, $showParents,
array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name']) array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name'], 'value' => $attributes['value'])
)); ));


$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend'; $template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend';
Expand Down Expand Up @@ -1963,11 +1962,11 @@ protected function _name($options = array(), $field = null, $key = 'name') {
* @access private * @access private
* @return array * @return array
*/ */
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) { function __selectOptions($elements = array(), $parents = array(), $showParents = null, $attributes = array()) {
$select = array(); $select = array();
$attributes = array_merge(array('escape' => true, 'style' => null), $attributes); $attributes = array_merge(array('escape' => true, 'style' => null, 'value' => null), $attributes);
$selectedIsEmpty = ($selected === '' || $selected === null); $selectedIsEmpty = ($attributes['value'] === '' || $attributes['value'] === null);
$selectedIsArray = is_array($selected); $selectedIsArray = is_array($attributes['value']);


foreach ($elements as $name => $title) { foreach ($elements as $name => $title) {
$htmlOptions = array(); $htmlOptions = array();
Expand All @@ -1981,7 +1980,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
$parents[] = $name; $parents[] = $name;
} }
$select = array_merge($select, $this->__selectOptions( $select = array_merge($select, $this->__selectOptions(
$title, $selected, $parents, $showParents, $attributes $title, $parents, $showParents, $attributes
)); ));


if (!empty($name)) { if (!empty($name)) {
Expand All @@ -2002,8 +2001,8 @@ function __selectOptions($elements = array(), $selected = null, $parents = array


if ($name !== null) { if ($name !== null) {
if ( if (
(!$selectedIsArray && !$selectedIsEmpty && (string)$selected == (string)$name) || (!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) ||
($selectedIsArray && in_array($name, $selected)) ($selectedIsArray && in_array($name, $attributes['value']))
) { ) {
if ($attributes['style'] === 'checkbox') { if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true; $htmlOptions['checked'] = true;
Expand Down

0 comments on commit 6d97aed

Please sign in to comment.