DataObjectManager
DataObjectManager copied to clipboard
Patch: Update FilteredDropdownSet so that returnLabel can also be a method instead of a field.
I needed to use a FilteredDropdownSet, but the label in the dependent dropdown box came from a method (e.g., getFullName()) instead of a single database field. This required a small modification to the FilteredDropdownSet. I think that this might be useful for others too.
The change is too small for me to bother forking the project and sending a pull request, so here's the patch:
code/dropdown_fields/FilteredDropdownSet.php | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/code/dropdown_fields/FilteredDropdownSet.php b/code/dropdown_fields/FilteredDropdownSet.php index 09da7dd..64267e6 100755 --- a/code/dropdown_fields/FilteredDropdownSet.php +++ b/code/dropdown_fields/FilteredDropdownSet.php @@ -52,7 +52,9 @@ class FilteredDropdownSet extends FieldGroup { $results = DataObject::get($this->sourceClass, $filter); if($results) { foreach($results as $r) {
-
$ret[$r->{$this->returnKey}] = $r->{$this->returnLabel};
-
$ret[$r->{$this->returnKey}] =
-
($r->hasMethod($this->returnLabel) ?
-
-- 1.7.7.GIT$r->{$this->returnLabel}(): $r->{$this->returnLabel}); } } return Convert::array2json($ret);