Hi ,
Thanks for the awesome module. With the help of this module I have created a custom route to display multiple content types. And I also checked the include,sort and pagination. Everything is working as expected. But Am trying to add a filter condition in the API URL but it doesn't seems to be working.
Can anyone help me out how can we add the filter parameter in the API call ?
Thanks in Advance.
Issue fork jsonapi_resources-3114758
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sam711 commentedWhat you're describing sounds like JSON:API Cross Bundles (https://www.drupal.org/project/jsonapi_cross_bundles)
If you still need to do it yourself, have you looked at how this is done in
\Drupal\jsonapi\Controller\EntityResource::getCollectionQuery? The $params array comes fromgetJsonApiParams.May be this is worth a Trait 🤔
Comment #3
suresh7787 commentedHi sam711,
Thanks for your response. I have tried jsonapi_cross_bundles. The module works fine with with core jsonapi, but if the site has jsonapi_extras enabled, the cross bundles module didnt work as expected. (i.e) jsonapi/node throws 404.
If I disabled the jsonapi_extras it is working fine. So that is the reason, Am using jsonapi_resources module.
Let me have a look at your advise and will keep you posted.
Thanks again.
Comment #4
sarbazx commentedHI suresh7787,
Did you able to filter on custom resources? Can you share how did you did it?
Thanks.
Comment #5
ptmkenny commentedDiscussion with @mglaman on Slack:
Comment #6
ptmkenny commentedI started on an MR for this.
To get filters to work, you need to add the following code to the
process()method of your custom JSON:API resource:However, the filters don't currently work because I don't understand how to get the resource type (see the comment in the MR code).Filtering support is available. It works for me, but your mileage may vary.
Comment #8
ptmkenny commentedAn important note for filtering: the order of
_jsonapi_resource_typesinmymodule.routing.ymlis important.The first entity type listed must be the base for the entity query; if you put them in a random order, filters like
entity_reference_field.referenced_entity_fieldwill fail.Comment #9
sarbazx commentedHello,
is this fixed?
Comment #10
ptmkenny commented@sarbazx No, it's not fixed. If it was fixed, the status would be "Fixed", not "Needs work".
I wrote the MR and it works for me. But it doesn't have any tests (which probably need to be created for it to be merged), and no one else has reported using it successfully, so I don't know how well it works for other use cases. For my own site, it's working great.
Comment #11
ptmkenny commentedWith claude code, I made the following changes to the MR:
Comment #12
ptmkenny commentedI have tested this locally against my React app.
With regard to the MR, I'm not sure if the new setter-injected dependencies are permissible or not:
Other than that, I think this is ready for review, so I am removing the "Draft" status from the MR.
Comment #13
mglamanThanks ptmkenny! I'll get this reviewed and committed tomorrow
Comment #14
mglamanComment #16
mglamanthank you, merged! I'll release soon
Comment #18
ptmkenny commentedThank you for fixing and committing, and thank you for the help getting this started in the first place!