Permalink
Browse files

Merge pull request #443 from halkyon/sapphire

---
  • Loading branch information...
chillu committed May 14, 2012
2 parents ce3b2fc + 9da92e0 commit 0a6ec3d9c996faf1c17dffc467e17dbffe6d5ddc
Showing with 43 additions and 32 deletions.
  1. +2 −2 forms/CompositeField.php
  2. +8 −8 forms/FieldList.php
  3. +21 −10 forms/FormField.php
  4. +12 −12 tests/forms/FieldListTest.php
View
@@ -248,8 +248,8 @@ public function replaceField($fieldName, $newField) {
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;
}
View
@@ -40,7 +40,7 @@ public function __construct($items = array()) {
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 @@ public function dataFieldByName($name) {
foreach($dataFields as $child) {
if(trim($name) == trim($child->getName()) || $name == $child->id) return $child;
}
- }
+ }
}
/**
@@ -343,7 +343,7 @@ public function dataFieldByName($name) {
*/
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 @@ public function insertBefore($item, $name) {
*/
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 @@ public function insertAfter($item, $name) {
*/
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 @@ public function push($item, $key = null) {
*/
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 @@ public function transform($trans) {
/**
* 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;
}
View
@@ -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 @@ function Required() {
}
}
+ 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);
}
}
@@ -386,7 +386,7 @@ function testInsertAfterFieldToSet() {
$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 @@ function testrootFieldSet() {
)
);
- /* 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() {

0 comments on commit 0a6ec3d

Please sign in to comment.