From 970a453cb83c5eee9fedcc6e8bcb8b1907fa598e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 16 Sep 2007 16:06:52 +0000 Subject: [PATCH] bfojcapell: Added function insertBeforeRecursive (see www.silverstripe.com/google-summer-of-code-forum/show/3005). This function is only called in Translatable.php at this moment, so if finally insertBefore gets a recursive behaviour then the call can be renamed and insertBeforeRecursive deleted. (merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42113 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/FieldSet.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/forms/FieldSet.php b/forms/FieldSet.php index 3a8460771..156bd5feb 100755 --- a/forms/FieldSet.php +++ b/forms/FieldSet.php @@ -179,6 +179,37 @@ class FieldSet extends DataObjectSet { $this->items[] = $item; } + + /** + * Inserts an item before the item with name $name + * It can be buried in a composite field + * If no item with name $name is found, $item is inserted at the end of the FieldSet + * + * @param FormField $item The item to be inserted + * @param string $name The name of the item that $item should be before + * @param int $level For internal use only, should not be passed + */ + public function insertBeforeRecursive($item, $name, $level = 0) { + if($this->sequentialSet) $this->sequentialSet = null; + $i = 0; + foreach($this->items as $child) { + if($name == $child->Name() || $name == $child->id) { + array_splice($this->items, $i, 0, array($item)); + + return $level; + } else if($child->isComposite()) { + if($level = $child->insertBeforeRecursive($item,$name,$level+1)) return $level; + } + + $i++; + } + if ($level === 0) { + $this->items[] = $item; + return 0; + } + return false; + } + public function insertAfter($item, $name) { if($this->sequentialSet) $this->sequentialSet = null;