10000 [Form] ArrayChoiceList can now deal with a null in choices by issei-m · Pull Request #17502 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] ArrayChoiceList can now deal with a null in choices #17502

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Form] ArrayChoiceList can now deal with a null in choices
  • Loading branch information
issei-m committed Jan 23, 2016
commit 68292bb52b739b47d7f7d4293a2dd98ac05122ab
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getChoicesForValues(array $values)
$choices = array();

foreach ($values as $i => $givenValue) {
if (isset($this->choices[$givenValue])) {
if (array_key_exists($givenValue, $this->choices)) {
$choices[$i] = $this->choices[$givenValue];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ public function testCompareChoicesByIdentityByDefault()
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
}

public function testGetChoicesForValuesWithContainingNull()
{
$choiceList = new ArrayChoiceList(array('Null' => null));

$this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0')));
}
}
0