-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Autocomplete] implement max_results option #478
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! We could use a test - I'm thinking that FieldAutocompleterTest
would be a good spot. We could add a new test method that creates, for example, 10 categories. Then in CategoryAutocompleteType
we can pass max_results => 5
. Then in the test, we do some search and assert that we only see 5 results, not the full 10.
// if no max is set, set one | ||
if (!$queryBuilder->getMaxResults()) { | ||
$queryBuilder->setMaxResults(10); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably stay - for the (edge) case when someone is using this class but have their own custom EntityAutocompleterInterface
implementation (one whose createFilteredQueryBuilder
may not have the max results set).
This will make it so that setting to null
does NOT avoid limiting results. But, I think that's ok - I'm not sure you should ever return ALL results - that's a recipe for hydrating too many entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f46e34d
|
||
``max_results`` (default: 10) | ||
Allow you to control the reults number returned by a query on automatic endpoint. | ||
Set it to ``null`` if you don't want to limit results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line after this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 40c7632
@@ -258,7 +258,9 @@ to the options above, you can also pass: | |||
$qb->andWhere('entity.name LIKE :filter OR entity.description LIKE :filter') | |||
->setParameter('filter', '%'.$query.'%'); | |||
} | |||
|
|||
``max_results`` (default: 10) | |||
Allow you to control the reults number returned by a query on automatic endpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow you to control the reults number returned by a query on automatic endpoint. | |
Allow you to control the max number of results returned by the automatic autocomplete endpoint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 40c7632
OK I will correct your suggestions and I tel you when it's done |
Unit test added in commit f34e8b0 |
Outch don't know why CS is crying |
40c7632
to
289463d
Compare
This is fantastic work! Thank you @DarrHeLL! I'll check out the CI - it's just a code styling issue, and it doesn't look like the CI outputs in a very helpful way. |
…tity (daFish) This PR was merged into the 2.x branch. Discussion ---------- [Autocomplete] max_results option is not passed to parent entity | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | none <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT There seems to be an oversight from #478 when it comes to passing the option from types that use `#[AsEntityAutocompleteField]`. This fix removes the unsetting of `$options['max_results']` from the `AutocompleteEntityTypeSubscriber` to allow passing the information. I also extended the tests to cover this case. Commits ------- 43e74fe fix(autocomplete): max_results option is not passed to parent
Added max_results option in formType options to control the results number returned by a query on automatic endpoint.