mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Renamed setContainerFieldSet() to setContainerFieldList() to match the FieldList API.
API CHANGE Renamed rootFieldSet() to rootFieldList() to match the FieldList API.
This commit is contained in:
parent
a53cca8932
commit
9da92e04cf
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ 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.
|
||||
*
|
||||
* @param FieldList $containerFieldSet
|
||||
* @param FieldList $list
|
||||
* @return FieldList
|
||||
*/
|
||||
function setContainerFieldSet($containerFieldSet) {
|
||||
$this->containerFieldSet = $containerFieldSet;
|
||||
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 @@ 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() {
|
||||
|
Loading…
Reference in New Issue
Block a user