BUGFIX Accepting dot-notation in TabSet->fieldByName()

BUGFIX Using fieldByName() instead of dataFieldByName() in Form->handleField() to allow rendering of nested tabs through a URL

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81128 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-07-06 21:53:50 +00:00
parent fcc6948e79
commit 4a531820cd
3 changed files with 19 additions and 2 deletions

View File

@ -289,7 +289,7 @@ class Form extends RequestHandler {
* Handle a field request
*/
function handleField($request) {
return $this->dataFieldByName($request->param('FieldName'));
return $this->Fields()->fieldByName($request->param('FieldName'));
}
/**

View File

@ -83,8 +83,22 @@ class TabSet extends CompositeField {
* Returns the named tab
*/
public function fieldByName($name) {
if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2);
else $remainder = null;
foreach($this->children as $child) {
if($name == $child->Name || $name == $child->id) return $child;
if(trim($name) == trim($child->Name) || $name == $child->id) {
if($remainder) {
if($child->isComposite()) {
return $child->fieldByName($remainder);
} else {
user_error("Trying to get field '$remainder' from non-composite field $child->class.$name", E_USER_WARNING);
return null;
}
} else {
return $child;
}
}
}
}

View File

@ -235,6 +235,9 @@ class FieldSetTest extends SapphireTest {
/* We have 1 field for each of the tabs */
$this->assertEquals(1, $mainTab->Fields()->Count());
$this->assertEquals(1, $otherTab->Fields()->Count());
$this->assertNotNull($fields->fieldByName('Root.Content'));
$this->assertNotNull($fields->fieldByName('Root.Content.Main'));
}
function testTabTitles() {