Views API to include filters/sorting

Created on 19 February 2024, 4 months ago
Updated 18 March 2024, 3 months ago

It is fantastic that views is now working right out of the box along with pagination. Would you be looking to add in filters/sorting to the API. From a functionality stand point this would be invaluable. You would have access to an array of simple or complex filtering depending on your apps needs. This would also be one less API lookup as well.

"content": {
  "element": "drupal-view",
  "title": "Articles",
  "viewId": "articles",
  "displayId": "custom_elements_page_1",
  "args": [],
  "filters": [
  ]
  "pager": {
    "totalPages": 1,
    "current": 0
  },
}

Would love to know if that is in the pipeline?

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States glynster

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @glynster
  • πŸ‡¦πŸ‡ΉAustria fago Vienna

    I agree that would be a very valuable addition.

    I think a first step would be to make sure this is supported by passing through all the necessary information, such that the built-in view component can do the sorting + add its own custom filter form.

    As a second, later step, we could look into shipping with working drupal-forms for exposed filters and sorts - after πŸ“Œ Add support for forms Needs review landed.

    That said, we don't currently have plans to work on this, since we are focussing on RC1 topics to get that out of the door, see https://www.drupal.org/project/lupus_decoupled/issues/3311105#comment-15... πŸ“Œ [META] Roadmap Active

    That said, of course contributions are welcome if you'd like to give it a go. I'd happy to chat and provide pointers for necessary changes.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Great news and it make sense, due to the forms support. We have been playing around a little to get things working. This module and code provided some useful hints:

    https://git.drupalcode.org/project/views_better_rest/-/blob/1.0.x/src/Pl...

    If we get any success we would be happy to add this to a PR.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    I just ran a quick test with the module and this is exactly what you want.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Added as a patch and works well. I was not sure how to do a PR. Let me know if I need to adjust anything.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Is it possible for me to do a MR to help include the code better?

  • Status changed to Needs work 4 months ago
  • πŸ‡¦πŸ‡ΉAustria fago Vienna

    @glynster: Sure! Everone can create MRs, just add an issue fork and push your code there!

    thx for the patch. As I understand the code is taken from views_better_rest module?

    I'm wondering whether we should include this information always or maybe better make some checkboxes in the style-plugin to allow turning it on and off? I guess someone not needing that information does not want to bloat the API response of the view.

    + foreach ($handlers as $id => $item) {
    + if (!empty($item['exposed'])) {
    + $info = $item['expose'];
    + if ($type === 'filter') {

    I see the code handles the filter case, but I miss 'sort'. Is that missing?

    How are you handling things on the vue side? Anything we should document here then?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    @fago, I guess I missed the connection, I will go ahead and do the MR.

    I don't think we need to to do a check as in views you have an option to expose. So if they never expose the filters then it should not return anything in the API output. To me this makes sense. Let me add in the if check and take it from there.

    Once I have this done yes I can jump into the Vue side of things. We usually use something like vue multi-select. We have also been looking at Nuxt UI lately. Our current setup is Bootstrap 5.3. Totally off topic but would it make sense to offer a basic vue theme using Nuxt UI?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Added to git now. As I have looked no filtering or sorting is added to the API unless it is set to expose in Views. So I think that works fine. Let me know.

Production build 0.69.0 2024