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
This commit is contained in:
Ingo Schommer 2007-09-16 16:06:52 +00:00
parent 20f14f04af
commit 970a453cb8

View File

@ -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;