mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #220 from oddnoc/6817-findOrMakeTab
BUGFIX #6817: FieldList.php: findOrMakeTab () fails for nested TabSets
This commit is contained in:
commit
aa83c114a6
@ -256,7 +256,7 @@ class FieldList extends ArrayList {
|
|||||||
*/
|
*/
|
||||||
public function findOrMakeTab($tabName, $title = null) {
|
public function findOrMakeTab($tabName, $title = null) {
|
||||||
$parts = explode('.',$tabName);
|
$parts = explode('.',$tabName);
|
||||||
|
$last_idx = count($parts) - 1;
|
||||||
// We could have made this recursive, but I've chosen to keep all the logic code within FieldList rather than add it to TabSet and Tab too.
|
// We could have made this recursive, but I've chosen to keep all the logic code within FieldList rather than add it to TabSet and Tab too.
|
||||||
$currentPointer = $this;
|
$currentPointer = $this;
|
||||||
foreach($parts as $k => $part) {
|
foreach($parts as $k => $part) {
|
||||||
@ -266,13 +266,15 @@ class FieldList extends ArrayList {
|
|||||||
if(!$currentPointer) {
|
if(!$currentPointer) {
|
||||||
if(is_a($parentPointer, 'TabSet')) {
|
if(is_a($parentPointer, 'TabSet')) {
|
||||||
// use $title on the innermost tab only
|
// use $title on the innermost tab only
|
||||||
if($title && $k == count($parts)-1) {
|
if ($k == $last_idx) {
|
||||||
$currentPointer = new Tab($part, $title);
|
$currentPointer = isset($title) ? new Tab($part, $title) : new Tab($part);
|
||||||
} else {
|
}
|
||||||
$currentPointer = new Tab($part);
|
else {
|
||||||
|
$currentPointer = new TabSet($part);
|
||||||
}
|
}
|
||||||
$parentPointer->push($currentPointer);
|
$parentPointer->push($currentPointer);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$withName = ($parentPointer->hasMethod('Name')) ? " named '{$parentPointer->getName()}'" : null;
|
$withName = ($parentPointer->hasMethod('Name')) ? " named '{$parentPointer->getName()}'" : null;
|
||||||
user_error("FieldList::addFieldToTab() Tried to add a tab to object '{$parentPointer->class}'{$withName} - '$part' didn't exist.", E_USER_ERROR);
|
user_error("FieldList::addFieldToTab() Tried to add a tab to object '{$parentPointer->class}'{$withName} - '$part' didn't exist.", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user