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 merge direction #1571

Merged
merged 2 commits into from
Nov 7, 2021
Merged

Conversation

toooni
Copy link
Contributor

@toooni toooni commented Nov 4, 2021

Subject

This PR fixes an issue with non mapped filter made with CallbackFilter.

I am targeting this branch, because this bug was introduced and isn't present in any other branch.

Closes #1568

Changelog

### Fixed
- Fixed non mapped `CallbackFilter` datagrid filter.

@VincentLanglet VincentLanglet requested a review from a team November 4, 2021 16:29
Copy link
Member

@core23 core23 left a comment

Choose a reason for hiding this comment

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

Bonus points if you provide a test case for your change

@@ -91,9 +91,9 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
ModelFilter::class === $fieldDescription->getType() && null === $fieldDescription->getOption('field_type')
|| EntityType::class === $fieldDescription->getOption('field_type')
) {
$fieldDescription->mergeOption('field_options', [
$fieldDescription->setOption('field_options', array_merge([
Copy link
Member

Choose a reason for hiding this comment

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

If these offsets are strings, we could use + instead of array_merge().

Copy link
Member

Choose a reason for hiding this comment

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

Do you prefer $a + $b over array_merge($b, $a) or do we merge like this ?

Copy link
Member

Choose a reason for hiding this comment

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

IMO, avoiding a function call is better for performance reasons.

Copy link
Contributor Author

@toooni toooni Nov 5, 2021

Choose a reason for hiding this comment

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

I think array_merge is clearer and more descriptive.

Performance wise I've just found this: https://stackoverflow.com/questions/57192782/array-merge-vs-direct-array-injection-performance/57193666 which indicates that array_merge is faster.

Edit: Sorry, I've skipped a few lines. This doesn't compare with +.

Copy link
Member

Choose a reason for hiding this comment

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

It's just a suggestion, not a blocker for the fix.
We could make performance improvements in a new PR.
For the records: https://gist.github.com/Ocramius/8399625.

Copy link
Member

Choose a reason for hiding this comment

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

@phansys not sure it's still true, the comparison was done with PHP 5.4

@VincentLanglet VincentLanglet requested a review from a team November 5, 2021 08:31
@VincentLanglet VincentLanglet merged commit f2e741a into sonata-project:4.x Nov 7, 2021
@VincentLanglet
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-mapped CallbackFilter datagrid field does not work with EntityType field_type
5 participants