Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #220 from oddnoc/6817-findOrMakeTab

BUGFIX #6817: FieldList.php: findOrMakeTab () fails for nested TabSets
  • Loading branch information...
commit aa83c114a6238900000a0448e833fd4698b75f70 2 parents 603a984 + 5944484
Sam Minnée sminnee authored
Showing with 8 additions and 6 deletions.
  1. +8 −6 forms/FieldList.php
14 forms/FieldList.php
View
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.