Skip to content

Commit

Permalink
Merge pull request #443 from halkyon/sapphire
Browse files Browse the repository at this point in the history
---
  • Loading branch information
chillu committed May 14, 2012
2 parents ce3b2fc + 9da92e0 commit 0a6ec3d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
4 changes: 2 additions & 2 deletions forms/CompositeField.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ public function replaceField($fieldName, $newField) {
return $this->children->replaceField($fieldName, $newField); return $this->children->replaceField($fieldName, $newField);
} }


function rootFieldSet() { function rootFieldList() {
if(is_object($this->containerFieldSet)) return $this->containerFieldSet->rootFieldSet(); if(is_object($this->containerFieldList)) return $this->containerFieldList->rootFieldList();
else return $this->children; else return $this->children;
} }


Expand Down
16 changes: 8 additions & 8 deletions forms/FieldList.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($items = array()) {
parent::__construct($items); parent::__construct($items);


foreach ($items as $item) { foreach ($items as $item) {
if ($item instanceof FormField) $item->setContainerFieldSet($this); if ($item instanceof FormField) $item->setContainerFieldList($this);
} }
} }


Expand Down Expand Up @@ -332,7 +332,7 @@ public function dataFieldByName($name) {
foreach($dataFields as $child) { foreach($dataFields as $child) {
if(trim($name) == trim($child->getName()) || $name == $child->id) return $child; if(trim($name) == trim($child->getName()) || $name == $child->id) return $child;
} }
} }
} }


/** /**
Expand All @@ -343,7 +343,7 @@ public function dataFieldByName($name) {
*/ */
public function insertBefore($item, $name) { public function insertBefore($item, $name) {
$this->onBeforeInsert($item); $this->onBeforeInsert($item);
$item->setContainerFieldSet($this); $item->setContainerFieldList($this);


$i = 0; $i = 0;
foreach($this->items as $child) { foreach($this->items as $child) {
Expand All @@ -368,7 +368,7 @@ public function insertBefore($item, $name) {
*/ */
public function insertAfter($item, $name) { public function insertAfter($item, $name) {
$this->onBeforeInsert($item); $this->onBeforeInsert($item);
$item->setContainerFieldSet($this); $item->setContainerFieldList($this);


$i = 0; $i = 0;
foreach($this->items as $child) { foreach($this->items as $child) {
Expand All @@ -393,7 +393,7 @@ public function insertAfter($item, $name) {
*/ */
public function push($item, $key = null) { public function push($item, $key = null) {
$this->onBeforeInsert($item); $this->onBeforeInsert($item);
$item->setContainerFieldSet($this); $item->setContainerFieldList($this);
return parent::push($item, $key = null); return parent::push($item, $key = null);
} }


Expand All @@ -402,7 +402,7 @@ public function push($item, $key = null) {
*/ */
protected function onBeforeInsert($item) { protected function onBeforeInsert($item) {
$this->flushFieldsCache(); $this->flushFieldsCache();
if($item->getName()) $this->rootFieldSet()->removeByName($item->getName(), true); if($item->getName()) $this->rootFieldList()->removeByName($item->getName(), true);
} }




Expand Down Expand Up @@ -479,8 +479,8 @@ public function transform($trans) {
/** /**
* Returns the root field set that this belongs to * Returns the root field set that this belongs to
*/ */
public function rootFieldSet() { public function rootFieldList() {
if($this->containerField) return $this->containerField->rootFieldSet(); if($this->containerField) return $this->containerField->rootFieldList();
else return $this; else return $this;
} }


Expand Down
31 changes: 21 additions & 10 deletions forms/FormField.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class FormField extends RequestHandler {
/** /**
* Stores a reference to the FieldList that contains this object. * Stores a reference to the FieldList that contains this object.
* @var FieldList * @var FieldList
*/ */
protected $containerFieldSet; protected $containerFieldList;


/** /**
* @var boolean * @var boolean
Expand Down Expand Up @@ -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 * @param FieldList $list
*/ * @return FieldList
function setContainerFieldSet($containerFieldSet) { */
$this->containerFieldSet = $containerFieldSet; function setContainerFieldList($list) {
$this->containerFieldList = $list;
return $this; return $this;
} }

function rootFieldSet() { function rootFieldSet() {
if(is_object($this->containerFieldSet)) return $this->containerFieldSet->rootFieldSet(); Deprecation::notice('3.0', 'Use rootFieldList() instead.');
else user_error("rootFieldSet() called on $this->class object without a containerFieldSet", E_USER_ERROR); 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);
} }


} }
24 changes: 12 additions & 12 deletions tests/forms/FieldListTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ function testInsertAfterFieldToSet() {
$this->assertEquals('Title', $fields[1]->getName()); $this->assertEquals('Title', $fields[1]->getName());
} }


function testrootFieldSet() { function testrootFieldList() {
/* Given a nested set of FormField, CompositeField, and FieldList objects */ /* Given a nested set of FormField, CompositeField, and FieldList objects */
$FieldList = new FieldList( $FieldList = new FieldList(
$root = new TabSet("Root", $root = new TabSet("Root",
Expand All @@ -397,22 +397,22 @@ function testrootFieldSet() {
) )
); );


/* rootFieldSet() should always evaluate to the same object: the topmost FieldList */ /* rootFieldList() should always evaluate to the same object: the topmost FieldList */
$this->assertSame($FieldList, $FieldList->rootFieldSet()); $this->assertSame($FieldList, $FieldList->rootFieldList());
$this->assertSame($FieldList, $root->rootFieldSet()); $this->assertSame($FieldList, $root->rootFieldList());
$this->assertSame($FieldList, $main->rootFieldSet()); $this->assertSame($FieldList, $main->rootFieldList());
$this->assertSame($FieldList, $a->rootFieldSet()); $this->assertSame($FieldList, $a->rootFieldList());
$this->assertSame($FieldList, $b->rootFieldSet()); $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")); $root->push($other = new Tab("Other"));
$other->push($c = new TextField("C")); $other->push($c = new TextField("C"));
$root->push($third = new Tab("Third", $d = new TextField("D"))); $root->push($third = new Tab("Third", $d = new TextField("D")));


$this->assertSame($FieldList, $other->rootFieldSet()); $this->assertSame($FieldList, $other->rootFieldList());
$this->assertSame($FieldList, $third->rootFieldSet()); $this->assertSame($FieldList, $third->rootFieldList());
$this->assertSame($FieldList, $c->rootFieldSet()); $this->assertSame($FieldList, $c->rootFieldList());
$this->assertSame($FieldList, $d->rootFieldSet()); $this->assertSame($FieldList, $d->rootFieldList());
} }


function testAddingDuplicateReplacesOldField() { function testAddingDuplicateReplacesOldField() {
Expand Down

0 comments on commit 0a6ec3d

Please sign in to comment.