mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #245 from halkyon/master
SS_Map_Iterator checks for hasMethod() (brought over from DataObjectSet::map() in 2.4)
This commit is contained in:
commit
1b97c827dc
@ -165,7 +165,9 @@ class SS_Map_Iterator implements Iterator {
|
||||
if(isset($this->firstItems[$this->firstItemIdx])) {
|
||||
return $this->firstItems[$this->firstItemIdx][1];
|
||||
} else {
|
||||
if($rewoundItem) return $rewoundItem->{$this->titleField};
|
||||
if($rewoundItem) return ($rewoundItem->hasMethod($this->titleField))
|
||||
? $rewoundItem->{$this->titleField}()
|
||||
: $rewoundItem->{$this->titleField};
|
||||
}
|
||||
|
||||
}
|
||||
@ -174,7 +176,9 @@ class SS_Map_Iterator implements Iterator {
|
||||
if(isset($this->firstItems[$this->firstItemIdx])) {
|
||||
return $this->firstItems[$this->firstItemIdx][1];
|
||||
} else {
|
||||
return $this->items->current()->{$this->titleField};
|
||||
return ($this->items->current()->hasMethod($this->titleField))
|
||||
? $this->items->current()->{$this->titleField}()
|
||||
: $this->items->current()->{$this->titleField};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1051,11 @@ class DataObjectTest_Team extends DataObject implements TestOnly {
|
||||
'Position' => 'Varchar(100)'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
function MyTitle() {
|
||||
return 'Team ' . $this->Title;
|
||||
}
|
||||
|
||||
function getDynamicField() {
|
||||
return 'dynamicfield';
|
||||
}
|
||||
|
@ -68,6 +68,20 @@ class SS_MapTest extends SapphireTest {
|
||||
), $map->keys());
|
||||
}
|
||||
|
||||
function testMethodAsValueField() {
|
||||
$list = DataList::create('DataObjectTest_Team');
|
||||
$list->sort('Title');
|
||||
$map = new SS_Map($list, 'ID', 'MyTitle');
|
||||
$this->assertEquals(array(
|
||||
'Team Subteam 1',
|
||||
'Team Subteam 2',
|
||||
'Team Subteam 3',
|
||||
'Team Team 1',
|
||||
'Team Team 2',
|
||||
'Team Team 3'
|
||||
), $map->values());
|
||||
}
|
||||
|
||||
function testValues() {
|
||||
$list = DataList::create('DataObjectTest_TeamComment');
|
||||
$list->sort('Name');
|
||||
@ -129,4 +143,4 @@ class SS_MapTest extends SapphireTest {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user