Skip to content

Commit

Permalink
Merge pull request #220 from oddnoc/6817-findOrMakeTab
Browse files Browse the repository at this point in the history
BUGFIX #6817: FieldList.php: findOrMakeTab () fails for nested TabSets
  • Loading branch information
sminnee committed Mar 9, 2012
2 parents 603a984 + 5944484 commit aa83c11
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions forms/FieldList.php
Expand Up @@ -256,7 +256,7 @@ public function hasTabSet() {
*/
public function findOrMakeTab($tabName, $title = null) {
$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.
$currentPointer = $this;
foreach($parts as $k => $part) {
Expand All @@ -266,13 +266,15 @@ public function findOrMakeTab($tabName, $title = null) {
if(!$currentPointer) {
if(is_a($parentPointer, 'TabSet')) {
// use $title on the innermost tab only
if($title && $k == count($parts)-1) {
$currentPointer = new Tab($part, $title);
} else {
$currentPointer = new Tab($part);
if ($k == $last_idx) {
$currentPointer = isset($title) ? new Tab($part, $title) : new Tab($part);
}
else {
$currentPointer = new TabSet($part);
}
$parentPointer->push($currentPointer);
} else {
}
else {
$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);
}
Expand Down

0 comments on commit aa83c11

Please sign in to comment.