Skip to content
Permalink
Browse files

made source context pass through to next source if no value found for…

… context source
  • Loading branch information...
Jonas Hartmann
Jonas Hartmann committed Aug 26, 2016
1 parent 4eecbfe commit f7d1ddd4048d62ecf52962794bd535d577edefda
Showing with 31 additions and 9 deletions.
  1. +6 −9 src/View/Helper/FormHelper.php
  2. +25 −0 tests/TestCase/View/Helper/FormHelperTest.php
@@ -2733,17 +2733,14 @@ public function getSourceValue($fieldname, $options = [])
{
foreach ($this->getValuesSources() as $valuesSource) {
if ($valuesSource === 'context') {
return $this->_getContext()->val($fieldname, $options);
}
if ($this->request->{$valuesSource}($fieldname) !== null) {
$val = $this->_getContext()->val($fieldname, $options);
if ($val !== null) {
return $val;
}
} elseif ($this->request->{$valuesSource}($fieldname) !== null) {
return $this->request->{$valuesSource}($fieldname);
}
}
if (isset($options['default'])) {
return $options['default'];
}
if (isset($options['schemaDefault'])) {
return $options['schemaDefault'];
}
return null;
}
}
@@ -8556,4 +8556,29 @@ public function testFormValuesSourcesDefaults()
$expected = ['input' => ['type' => 'password', 'name' => 'password', 'value' => 'helloworld']];
$this->assertHtml($expected, $result);
}
/**
* Test sources values schema defaults handling
*
* @return void
*/
public function testSourcesValueDoesntExistPassThrough()
{
$this->Form->request->query['category'] = 'sesame-cookies';
$Articles = TableRegistry::get('Articles');
$entity = $Articles->newEntity();
$this->Form->create($entity);
$this->Form->setValuesSources(['query', 'context']);
$result = $this->Form->getSourceValue('category');
$expected = 'sesame-cookies';
$this->assertEquals($expected, $result);
$this->Form->setValuesSources(['context', 'query']);
$result = $this->Form->getSourceValue('category');
$expected = 'sesame-cookies';
$this->assertEquals($expected, $result);
}
}

0 comments on commit f7d1ddd

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