Skip to content

Commit fbc901b

Browse files
authored
Merge pull request #7 from sebastiand/patch-1
Fix broken getSourceAsArray() function
2 parents f66d11d + 2f024c6 commit fbc901b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

code/DropdownImageField.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,24 @@ public function Field($properties = array()) {
8686
public function getSource() {
8787
return $this->source;
8888
}
89+
90+
/**
91+
* Get the source of this field as an array
92+
* Transform the source DataList to an key => value array
93+
*
94+
* @return array
95+
*/
96+
public function getSourceAsArray()
97+
{
98+
$source = $this->getSource();
99+
if (is_array($source)) {
100+
return $source;
101+
} else {
102+
$sourceArray = array();
103+
foreach ($source as $object) {
104+
$sourceArray[$object->{$this->keyField}] = $object->{$this->labelField};
105+
}
106+
}
107+
return $sourceArray;
108+
}
89109
}

0 commit comments

Comments
 (0)