Changeset 9539
- Timestamp:
- 06/11/08 12:02:48 (5 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/plugins/sfCompat10Plugin/lib/util/sfFillInForm.class.php
r9217 r9539 226 226 } 227 227 228 return null !== sfToolkit::getArrayValueForPath($values, $name);228 return sfToolkit::hasArrayValueForPath($values, $name); 229 229 } 230 230 … … 234 234 if (array_key_exists($name, $values)) 235 235 { 236 $return = $values[$name];237 if ($shiftArray && is_array($return))238 {239 // we need to remove the first element from the array. Therefore we need a reference240 $arrayRef = &$values[$name]; 241 $return = array_shift($arrayRef);242 }243 return $return;244 }245 246 return sfToolkit::getArrayValueForPath($values, $name);236 $return = &$values[$name]; 237 } else { 238 $return = &sfToolkit::getArrayValueForPath($values, $name); 239 } 240 241 if ($shiftArray && is_array($return)) 242 { 243 // we need to remove the first element from the array. Therefore we need a reference 244 return array_shift($return); 245 } 246 return $return; 247 247 } 248 248 branches/1.1/lib/plugins/sfCompat10Plugin/test/unit/util/sfFillInFormTest.php
r9495 r9539 12 12 require_once(dirname(__FILE__).'/../../../lib/util/sfFillInForm.class.php'); 13 13 14 $t = new lime_test(7 2, new lime_output_color());14 $t = new lime_test(74, new lime_output_color()); 15 15 16 16 $html = <<<EOF … … 45 45 </select> 46 46 <input name="article[or][much][longer]" value="very long!"/> 47 <input name="article[description][]" value="default description" /> 48 <input name="article[description][]" value="default description2" /> 47 49 <input name="multiple_text[]" value="text1"/> 48 50 <input name="multiple_text[]" value="text2"/> … … 99 101 $t->is($xml->xpath('//form[@name="form1"]/select[@name="articles[]"][1]/option[@selected="selected"]'), array(2, 3), '->fillInDom() preserves default values for multiple select'); 100 102 $t->is($xml->xpath('//form[@name="form1"]/select[@name="articles[]"][2]/option[@selected="selected"]'), array(1, 3), '->fillInDom() preserves default values for multiple select'); 103 $t->is(get_input_value($xml, 'article[description][]'), array('default description', 'default description2'), '->fillInDom() preserves default values for long multiple text inputs (article[description][])'); 101 104 102 105 // check form selection by name … … 151 154 'select_multiple' => array('first', 'last'), 152 155 'textarea' => 'my content', 153 'article[title]' => 'my article title', 154 'article[category]' => array(1, 2), 156 'article' => array( 157 'title' => 'my article title', 158 'category' => array(1, 2), 159 'description' => array('new description', 'new description2'), 160 ), 155 161 'multiple_text[]' => array('m1', 'm2'), 156 162 'multiple_textarea[]' => array('a1', 'a2'), … … 169 175 $t->is($xml->xpath('//form[@name="form1"]/textarea[@name="textarea"]'), array('my content'), '->fillInDom() fills in values for textarea'); 170 176 $t->is($xml->xpath('//form[@name="form1"]/select[@name="select"]/option[@selected="selected"]'), array('first'), '->fillInDom() fills in values for select'); 177 $t->is(get_input_value($xml, 'article[description][]'), array('new description', 'new description2'), '->fillInDom() fills in values for multiple text inputs in second dimension array'); 171 178 $t->is($xml->xpath('//form[@name="form1"]/select[@name="select_multiple"]/option[@selected="selected"]'), array('first', 'last'), '->fillInDom() fills in values for multiple select'); 172 179 $t->is(get_input_value($xml, 'article[title]'), 'my article title', '->fillInDom() fills in values for text input'); … … 221 228 $values = $xml->xpath($xpath); 222 229 223 if (count($values) > 1 )230 if (count($values) > 1 || substr($name,-2)=='[]') 224 231 { 225 232 foreach($values as $val) branches/1.1/lib/util/sfToolkit.class.php
r9190 r9539 483 483 * @return array 484 484 */ 485 public static function getArrayValueForPath($values, $name, $default = null)485 public static function &getArrayValueForPath(&$values, $name, $default = null) 486 486 { 487 487 if (false === $offset = strpos($name, '[')) 488 488 { 489 return isset($values[$name]) ? $values[$name] : $default; 489 $return = $default; 490 if (isset($values[$name])) 491 { 492 $return = &$values[$name]; 493 } 494 return $return; 490 495 } 491 496 … … 495 500 } 496 501 497 $array = $values[substr($name, 0, $offset)];502 $array = &$values[substr($name, 0, $offset)]; 498 503 499 504 while (false !== $pos = strpos($name, '[', $offset)) … … 513 518 return $default; 514 519 } 515 $array = $array[substr($name, $pos + 1, $end - $pos - 1)];520 $array = &$array[substr($name, $pos + 1, $end - $pos - 1)]; 516 521 $offset = $end; 517 522 }