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

fix up ListboxField #3767

Closed
wants to merge 1 commit into from
Closed

fix up ListboxField #3767

wants to merge 1 commit into from

Conversation

sunnysideup
Copy link
Contributor

fix doc information on the __construct method
allow SS_Map as source (just like parent class DropdownField)
I am wondering if the set / get source method could be simpler - more like the dropdown field...

fix doc information on the __construct method
allow SS_Map as source (just like parent class DropdownField)
I am wondering if the set / get source method could be simpler - more like the dropdown field...
@kinglozzer
Copy link
Member

@sunnysideup Do you have an example setup that failed prior to this change? I just tested and ListboxField already seems to work with an SS_Map source

@sunnysideup
Copy link
Contributor Author

Hi @kinglozzer , look at getSource, it checks for commas in arrays. That gave me an error.

@sunnysideup
Copy link
Contributor Author

my pull request needs work, but I do think it needs fixing. I will make another one.

@kinglozzer
Copy link
Member

Sorry, @sunnysideup, you’re quite right: for some reason I had warnings suppressed in my dev environment! 😳

What do you think of the following approach (casting $source to an array)?

$hasCommas = array_filter(
    array_keys((array) $source),
    create_function('$key', 'return strpos($key, ",") !== FALSE;')
);

By doing it this way, the original $source variable will stay as an SS_Map. My thinking here is that if you call setSource() with an SS_Map, then call getSource() you might not expect it to have been converted to an array.

Given that the parent class accepts either an SS_Map or an array, I’d argue that this is a bug so you could make your pull request against the 3.1 branch instead of master. You could also fix the docs for DropdownField::__construct(), DropdownField::setSource() and DropdownField::getSource() as none of them mentions SS_Map even though it’s supported.

@dhensby
Copy link
Contributor

dhensby commented Jan 8, 2015

Please can we get a test to prove this bug?

@stevie-mayhew
Copy link
Contributor

Its doesn't strictly have to be an SS_Map, just something with ArrayAccess - https://github.com/silverstripe/silverstripe-framework/blob/master/forms/DropdownField.php#L122

@dhensby
Copy link
Contributor

dhensby commented Jan 22, 2016

closing due to age and because the root cause of this problem will be resolved by having a more consistent API with SS_List

@dhensby dhensby closed this Jan 22, 2016
@tractorcow
Copy link
Contributor

Also this field would have been changed when I did my listfield redux. ;)

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

Successfully merging this pull request may close these issues.

None yet

5 participants