mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
fcc6948e79
commit
4a531820cd
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user