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

Set preserve_keys in array_slice to keep numeric array key association #7531

Merged
merged 1 commit into from
Jun 16, 2018

Conversation

Boorj
Copy link
Contributor

@Boorj Boorj commented Jun 16, 2018

Fixes #7411

In Form\Resolve\Choice.php array_slice clears indices of original associative array.

$ind = 0;
foreach ($field->get('values', []) as $key => $value) {
if ($limit !== null) {
if ($ind > $limit)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline control structures are not allowed

@@ -105,7 +105,19 @@ private function getValues(array $field)
*/
private function getYamlValues(Bag $field)
{
$values = array_slice($field->get('values', []), 0, $field->get('limit'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just need to add true as the 4th parameter to array_slice() to do natively what you're recreating below 😉

$values = array_slice($field->get('values', []), 0, $field->get('limit'), true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay! 😀
(actually, in such situations i dislike all those complex polymorphic functions)

@Boorj
Copy link
Contributor Author

Boorj commented Jun 16, 2018

@GawainLynch thank you for help. And for test.

@GwendolenLynch GwendolenLynch changed the title Remove incorrect array_slice from Choice.php Set preserve_keys in array_slice to keep numeric array key association Jun 16, 2018
@GwendolenLynch GwendolenLynch merged commit 36f4bc1 into bolt:3.5 Jun 16, 2018
@Boorj Boorj deleted the patch-12 branch June 16, 2018 20:28
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

3 participants