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: Make IsFirst and IsLast work as expected for PaginatedList (fixes #11465) #11471

Merged

Conversation

kinglozzer
Copy link
Member

@kinglozzer kinglozzer commented Nov 19, 2024

Description

Adds a fix for #11465 in CMS 5 that doesn’t risk a BC-break.

Manual testing steps

Set up a paginated list (e.g. in your Page class):

public function getPaginatedList()
{
    $items = [
        ['Val' => 1],
        ['Val' => 2],
        ['Val' => 3],
        ['Val' => 4],
        ['Val' => 5],
        ['Val' => 6],
        ['Val' => 7],
        ['Val' => 8],
        ['Val' => 9],
        ['Val' => 10],
    ];
    $list = new ArrayList($items);
    $paginated = new PaginatedList($list);
    $paginated->setPageLength(3);
    $paginated->setCurrentPage(2);
    return $paginated;
}

In a template, iterate through that paginated list:

<ul>
    <% loop $PaginatedList %>
    <li>$FirstLast $Val</li>
    <% end_loop %>
</ul>

Verify that the output is:

    first 4
    5
    last 6

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

LGTM for CMS 5.

Note this won't merge up straight to CMS 6 since the template engine is in a separate repository for 6 - and I personally think changing the count() behaviour of PaginatedList is a cleaner long-term solution anyway.

Won't merge right away in case there's still some concern about this behaviour - I'll merge by the end of the week if nobody raises any concerns (if I forget just @ me)

@GuySartorelli GuySartorelli self-assigned this Nov 19, 2024
@GuySartorelli GuySartorelli merged commit 5e2f4b7 into silverstripe:5.3 Nov 24, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants