API CHANGE: Updated FieldSet to use ArrayList rather then DataObjectSet.

MINOR: Updated FieldSetTest since position information is no longer available on iterated objects.
This commit is contained in:
ajshort 2011-05-06 08:30:54 +10:00
parent a75abd5cd7
commit f0676c7d56
2 changed files with 15 additions and 19 deletions

View File

@ -1,11 +1,11 @@
<?php <?php
/** /**
* DataObjectSet designed for form fields. * A list designed to hold form field instances.
* It extends the DataObjectSet with the ability to get a sequential set of fields. *
* @package forms * @package forms
* @subpackage fields-structural * @subpackage fields-structural
*/ */
class FieldSet extends DataObjectSet { class FieldSet extends ArrayList {
/** /**
* Cached flat representation of all fields in this set, * Cached flat representation of all fields in this set,
@ -26,20 +26,16 @@ class FieldSet extends DataObjectSet {
*/ */
protected $containerField; protected $containerField;
public function __construct($items = null) { public function __construct($items = array()) {
// if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array if (!is_array($items) || func_num_args() > 1) {
// otherwise use the passed array $items = func_get_args();
$itemsArr = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items; }
parent::__construct($itemsArr);
parent::__construct($items);
if(isset($this->items) && count($this->items)) {
foreach($this->items as $item) { foreach ($items as $item) {
if(isset($item) && is_a($item, 'FormField')) { if ($item instanceof FormField) $item->setContainerFieldSet($this);
$item->setContainerFieldSet($this);
}
}
} }
} }
/** /**

View File

@ -333,7 +333,7 @@ class FieldSetTest extends SapphireTest {
$this->assertEquals(4, $fields->Count()); $this->assertEquals(4, $fields->Count());
/* The position of the Title field is at number 3 */ /* The position of the Title field is at number 3 */
$this->assertEquals(3, $fields->fieldByName('Title')->Pos()); $this->assertEquals('Title', $fields[2]->Name());
} }
function testInsertBeforeMultipleFields() { function testInsertBeforeMultipleFields() {
@ -383,7 +383,7 @@ class FieldSetTest extends SapphireTest {
$this->assertEquals(4, $fields->Count()); $this->assertEquals(4, $fields->Count());
/* The position of the Title field should be at number 2 */ /* The position of the Title field should be at number 2 */
$this->assertEquals(2, $fields->fieldByName('Title')->Pos()); $this->assertEquals('Title', $fields[1]->Name());
} }
function testRootFieldSet() { function testRootFieldSet() {