Permalink
Browse files

Merge pull request #220 from oddnoc/6817-findOrMakeTab

BUGFIX #6817: FieldList.php: findOrMakeTab () fails for nested TabSets
  • Loading branch information...
2 parents 603a984 + 5944484 commit aa83c114a6238900000a0448e833fd4698b75f70 @sminnee sminnee committed Mar 9, 2012
Showing with 8 additions and 6 deletions.
  1. +8 −6 forms/FieldList.php
View
14 forms/FieldList.php
@@ -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) {
@@ -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);
}

0 comments on commit aa83c11

Please sign in to comment.