diff --git a/forms/CompositeField.php b/forms/CompositeField.php index 9116457f9..6f336de56 100644 --- a/forms/CompositeField.php +++ b/forms/CompositeField.php @@ -248,8 +248,8 @@ class CompositeField extends FormField { return $this->children->replaceField($fieldName, $newField); } - function rootFieldSet() { - if(is_object($this->containerFieldSet)) return $this->containerFieldSet->rootFieldSet(); + function rootFieldList() { + if(is_object($this->containerFieldList)) return $this->containerFieldList->rootFieldList(); else return $this->children; } diff --git a/forms/FieldList.php b/forms/FieldList.php index 7261585e4..094d9a945 100644 --- a/forms/FieldList.php +++ b/forms/FieldList.php @@ -40,7 +40,7 @@ class FieldList extends ArrayList { parent::__construct($items); foreach ($items as $item) { - if ($item instanceof FormField) $item->setContainerFieldSet($this); + if ($item instanceof FormField) $item->setContainerFieldList($this); } } @@ -332,7 +332,7 @@ class FieldList extends ArrayList { foreach($dataFields as $child) { if(trim($name) == trim($child->getName()) || $name == $child->id) return $child; } - } + } } /** @@ -343,7 +343,7 @@ class FieldList extends ArrayList { */ public function insertBefore($item, $name) { $this->onBeforeInsert($item); - $item->setContainerFieldSet($this); + $item->setContainerFieldList($this); $i = 0; foreach($this->items as $child) { @@ -368,7 +368,7 @@ class FieldList extends ArrayList { */ public function insertAfter($item, $name) { $this->onBeforeInsert($item); - $item->setContainerFieldSet($this); + $item->setContainerFieldList($this); $i = 0; foreach($this->items as $child) { @@ -393,7 +393,7 @@ class FieldList extends ArrayList { */ public function push($item, $key = null) { $this->onBeforeInsert($item); - $item->setContainerFieldSet($this); + $item->setContainerFieldList($this); return parent::push($item, $key = null); } @@ -402,7 +402,7 @@ class FieldList extends ArrayList { */ protected function onBeforeInsert($item) { $this->flushFieldsCache(); - if($item->getName()) $this->rootFieldSet()->removeByName($item->getName(), true); + if($item->getName()) $this->rootFieldList()->removeByName($item->getName(), true); } @@ -479,8 +479,8 @@ class FieldList extends ArrayList { /** * Returns the root field set that this belongs to */ - public function rootFieldSet() { - if($this->containerField) return $this->containerField->rootFieldSet(); + public function rootFieldList() { + if($this->containerField) return $this->containerField->rootFieldList(); else return $this; } diff --git a/forms/FormField.php b/forms/FormField.php index dbc26b479..e3bfb1fe3 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -53,8 +53,8 @@ class FormField extends RequestHandler { /** * Stores a reference to the FieldList that contains this object. * @var FieldList - */ - protected $containerFieldSet; + */ + protected $containerFieldList; /** * @var boolean @@ -837,19 +837,30 @@ class FormField extends RequestHandler { } } + function setContainerFieldSet($list) { + Deprecation::notice('3.0', 'Use setContainerFieldList() instead.'); + return $this->setContainerFieldList($list); + } + /** - * Set the FieldList that contains this field. + * Set the FieldList that contains this field. * - * @param FieldList $containerFieldSet - */ - function setContainerFieldSet($containerFieldSet) { - $this->containerFieldSet = $containerFieldSet; + * @param FieldList $list + * @return FieldList + */ + function setContainerFieldList($list) { + $this->containerFieldList = $list; return $this; } - + function rootFieldSet() { - if(is_object($this->containerFieldSet)) return $this->containerFieldSet->rootFieldSet(); - else user_error("rootFieldSet() called on $this->class object without a containerFieldSet", E_USER_ERROR); + Deprecation::notice('3.0', 'Use rootFieldList() instead.'); + return $this->rootFieldList(); + } + + function rootFieldList() { + if(is_object($this->containerFieldList)) return $this->containerFieldList->rootFieldList(); + else user_error("rootFieldList() called on $this->class object without a containerFieldList", E_USER_ERROR); } } diff --git a/tests/forms/FieldListTest.php b/tests/forms/FieldListTest.php index c2df14cdf..c4e769a8b 100644 --- a/tests/forms/FieldListTest.php +++ b/tests/forms/FieldListTest.php @@ -386,7 +386,7 @@ class FieldListTest extends SapphireTest { $this->assertEquals('Title', $fields[1]->getName()); } - function testrootFieldSet() { + function testrootFieldList() { /* Given a nested set of FormField, CompositeField, and FieldList objects */ $FieldList = new FieldList( $root = new TabSet("Root", @@ -397,22 +397,22 @@ class FieldListTest extends SapphireTest { ) ); - /* rootFieldSet() should always evaluate to the same object: the topmost FieldList */ - $this->assertSame($FieldList, $FieldList->rootFieldSet()); - $this->assertSame($FieldList, $root->rootFieldSet()); - $this->assertSame($FieldList, $main->rootFieldSet()); - $this->assertSame($FieldList, $a->rootFieldSet()); - $this->assertSame($FieldList, $b->rootFieldSet()); + /* rootFieldList() should always evaluate to the same object: the topmost FieldList */ + $this->assertSame($FieldList, $FieldList->rootFieldList()); + $this->assertSame($FieldList, $root->rootFieldList()); + $this->assertSame($FieldList, $main->rootFieldList()); + $this->assertSame($FieldList, $a->rootFieldList()); + $this->assertSame($FieldList, $b->rootFieldList()); - /* If we push additional fields, they should also have the same rootFieldSet() */ + /* If we push additional fields, they should also have the same rootFieldList() */ $root->push($other = new Tab("Other")); $other->push($c = new TextField("C")); $root->push($third = new Tab("Third", $d = new TextField("D"))); - $this->assertSame($FieldList, $other->rootFieldSet()); - $this->assertSame($FieldList, $third->rootFieldSet()); - $this->assertSame($FieldList, $c->rootFieldSet()); - $this->assertSame($FieldList, $d->rootFieldSet()); + $this->assertSame($FieldList, $other->rootFieldList()); + $this->assertSame($FieldList, $third->rootFieldList()); + $this->assertSame($FieldList, $c->rootFieldList()); + $this->assertSame($FieldList, $d->rootFieldList()); } function testAddingDuplicateReplacesOldField() {