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

Sort does nothing on aliased entries #3194

Closed
radovanobal opened this issue Feb 3, 2021 · 8 comments
Closed

Sort does nothing on aliased entries #3194

radovanobal opened this issue Feb 3, 2021 · 8 comments

Comments

@radovanobal
Copy link

radovanobal commented Feb 3, 2021

Bug Description

If I pass a list of entries to the partial as

{{ if events }}
    {{ partial:link_list :items="events"}}
{{ /if }}

and then try to sort this as

        <div class="row mx-auto flex">
            {{ items sort="title:asc" }}

            <div class="md:col-3 xs:col-6 flex">
                {{ if movie }}
                    {{ partial:link_movie_grid }}
                {{ else }}
                    {{ partial:link_grid }}
                {{ /if }}
            </div>
            {{ /items }}
        </div>

Nothing happens the list gets printed in the same order as it did before.

How to Reproduce

Create a template that has a partial and pass a set of entries to the partial as a variable, then try and sort the set inside the partial

Extra Detail

template:

{{ partial:header }}
{{ if content }}
    {{ partial:text_in_center :text="content" style="no-icon"}}
{{ /if }}
{{ if programs }}
    {{ partial:cards :cards="programs"}}
{{ /if }}
{{ if events }}
    {{ partial:link_list :items="events"}}
{{ /if }}
{{ partial:image_grid_slider :items="partners_slides"}}

partial:

<section class="component link-list">

    <div class="container">
        {{ if event_list_title }}
        <div class="row" >
            <div class="col-12">
                <h2 class="h1 big font-OddeeNo2">
                    {{ event_list_title }}
                </h2>
            </div>
        </div>
        {{ /if }}

        <div class="row mx-auto flex">
            {{ items sort="title:asc" }}

            <div class="md:col-3 xs:col-6 flex">
                {{ if movie }}
                    {{ partial:link_movie_grid }}
                {{ else }}
                    {{ partial:link_grid }}
                {{ /if }}
            </div>
            {{ /items }}
        </div>
    </div>
</section>

Environment

Statamic version: 3.0.40 Pro
PHP version: 7.4.9

Fresh install from statamic/statamic

@jackmcdade
Copy link
Member

Doesn't seem to work outside the partial either. Can you confirm that? I think the partial isn't thee issue, but rather the sort modifier when applied to an Entries collection variable.

@jackmcdade
Copy link
Member

I've got this fixed in #3363. Just needs a team review.

@jackmcdade jackmcdade changed the title Sort does nothing if entry set passed to partial Sort does nothing on aliased entries Mar 11, 2021
@jackmcdade jackmcdade added the bug label Mar 11, 2021
@radovanobal
Copy link
Author

radovanobal commented Mar 12, 2021

yes it looks like this effects more than just partials

@Hesesses
Copy link

Hesesses commented Mar 14, 2021

I have a product entry (products collection) which has multiple reviews (linked entries).

Now when i'm looping:
{{ reviews }}
...
{{ /reviews }}

Everything works fine.

I would like to sort reviews by date {{ reviews sort="date" }} but that it not working.

I posted the above on Discord, this is probably the same bug?

@jasonvarga
Copy link
Member

Try manually applying the change in #3363 to see if it solves your issue.
Add the new code to vendor/statamic/cms/src/Modifiers/CoreModifiers.php

@Hesesses
Copy link

Hesesses commented Mar 15, 2021

@jasonvarga tested this and no changes for the ordering.

I modified my code to match @radovanobal

product.antlers.html

{{ if reviews }}
  {{ partial:partials/review_listing :items="reviews" }}
{{ /if }}

partial:

<div class="space-y-5">
        <ul class="divide-y divide-gray-200">
            {{ items sort="date:asc" }}
            <li class="py-4">
                <div class="flex space-x-3">
                    <div class="flex-1 space-y-1">
                        <div class="flex items-center justify-between">
                            <span class="text-sm font-medium">{{ title }} {{ partial:partials/stars rating="{ score }" }}</span>
                            <p class="text-sm text-gray-500">{{ date format="d.m.Y" }}</p>
                        </div>
                        <p class="text-sm text-gray-500">{{ content }}</p>
                    </div>
                </div>
            </li>
            {{ /items }}
        </ul>
    </div>

changing the sort="anything" doesnt change ordering. If i leave it only {{ items }}, then it seems to use manual orderable order (even its turned off)

My product.md has these:

reviews:
  - 5b161ec2-f9ae-471f-8842-f55904ae595d
  - 7beedb9b-ff32-4a3e-9b3f-823a184aefba
  - 7f652456-5890-47e0-8c50-9f8d4e0d68a8
  - 410c1dfc-1b96-4b11-86ce-1e413aaeb51b
  - 1ce664e8-6877-4f5c-8447-43c962a3d838
  - 7e2052c9-b6e3-45e1-a32b-fb2e989e5296
  - c67731f7-1e04-4915-bb4f-4e3fed24bd88
  .... +100 more

Not sure if this is related to this problem, but if I add {{ items | count }} to partial (outside of the loop) to display total amount of reviews, it breaks the {{ items }} loop

Statamic 3.0.46
PHP 7.4.8

@jackmcdade
Copy link
Member

@Hesesses The count issue is completely unrelated, but confirmed. I opened a separate issue for that here: #3374

@jackmcdade
Copy link
Member

@Hesesses and the reason the fix wasn't working is because i was testing with the collections tag and you had Entries fieldtype data. The PR has been updated to work with your use case now too. https://github.com/statamic/cms/pull/3363/files

jackmcdade added a commit that referenced this issue Mar 15, 2021
…eferences #3194 (#3363)

* Adds ability to sort DataCollection objects with the sort modifier. References #3184.

* Ensure Entries fieldtype returns an EntryCollection

* Refactor collect method for entries and relationships
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

No branches or pull requests

5 participants