Views: expose items per page as config option

Created on 30 January 2025, about 1 month ago

Problem/Motivation

I'm rendering a View and injecting arguments, but I also want to configure the amount of items to render.

Proposed resolution

  • Add extra optional number field to configuration of "eca_render_views" Action
  • Replace "views_embed_view" with the underlying implementation
  • If configuration, set the items per page
Feature request
Status

Active

Version

2.1

Component

Code

Created by

🇧🇪Belgium lammensj

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

Merge Requests

Comments & Activities

  • Issue created by @lammensj
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This sounds like an interesting improvement. I wonder, while being on it, if there are other properties too, that we may want to change at the same time.

  • 🇧🇪Belgium lammensj

    It depends a bit on how flexible you want it to be. If you search for "function set" on this page: https://api.drupal.org/api/drupal/core%21modules%21views%21src%21ViewExe..., you'll get a list of all the items you can alter/set before executing the View.

    For now, I'm just limiting it to the arguments (already there) and the items per page.

  • 🇧🇪Belgium lammensj

    However... Testing the change now... When I set the items per page on the View-object, it works when it's rendered initially. But the second page just loads the amount of items that is configured in the View itself...

  • Pipeline finished with Success
    about 1 month ago
    Total: 466s
    #410304
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Left a couple of comments in the MR.

    When I set the items per page on the View-object, it works when it's rendered initially. But the second page just loads the amount of items that is configured in the View itself.

    That's strange. Maybe we could check in the views block plugin and check how they've done it there.

  • 🇧🇪Belgium lammensj

    I've implemented your remarks, thank you for the feedback.

    Regarding the items being returned for the second "page", I believe it's an issue coming from Views Infinite Scroll. I'll link the ticket. But this shouldn't stop this particular feature request.

  • Pipeline finished with Success
    26 days ago
    Total: 490s
    #414776
  • 🇧🇪Belgium lammensj

    For reference, this is how the Views Block plugin is overriding the items_per_page config item: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views.... The ECA Action is doing the same thing.

  • Pipeline finished with Failed
    26 days ago
    Total: 353s
    #414835
  • Pipeline finished with Success
    26 days ago
    Total: 462s
    #414843
  • 🇩🇪Germany jurgenhaas Gottmadingen

    The MR looks great. We probably need a update hook so that existing models will be updated for the new config property.

    Having said that, the default value of the items_per_page should probably be an empty string, not NULL.

    Following your comment #7, does that mean that it works correctly if Views Infinite Scroll is disabled?

Production build 0.71.5 2024