Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch: Update FilteredDropdownSet so that returnLabel can also be a method instead of a field. #50

Open
hdrlab opened this issue Apr 10, 2012 · 0 comments

Comments

@hdrlab
Copy link
Contributor

hdrlab commented Apr 10, 2012

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) ? 
    
  •                   $r->{$this->returnLabel}(): $r->{$this->returnLabel});
        }  
    }
    return Convert::array2json($ret);
    
    --
    1.7.7.GIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant