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

[5.x] Fix collection taxonomy/term URL #10439

Open
wants to merge 18 commits into
base: 5.x
Choose a base branch
from

Conversation

aerni
Copy link
Contributor

@aerni aerni commented Jul 11, 2024

This PR fixes an issue where a taxonomy or term with attached collection would return the wrong URL if the collection didn't have a mount. It does so by providing the collection handle as a fallback, which aligns with the taxonomy routing docs.

If a collection has a mount, the mount URL will be used and …

  • … the collection taxonomy route is /{collection-url}/{taxonomy-slug}
  • … the collection term route is /{collection-url}/{taxonomy-slug}/{term-slug}

If a collection has no mount the collection handle will be used and …

  • … the collection taxonomy route is /{collection-handle}/{taxonomy-slug}
  • … the collection term route is /{collection-handle}/{taxonomy-slug}/{term-slug}

@aerni aerni marked this pull request as ready for review July 11, 2024 18:36
@aerni aerni marked this pull request as draft July 11, 2024 19:50
@aerni aerni marked this pull request as ready for review July 12, 2024 13:37
@jasonvarga
Copy link
Member

return the wrong URL if the collection didn't have a mount

If the collection doesn't have a mount, it doesn't have a URL.

It does so by providing the collection handle as a fallback, which aligns with the taxonomy routing docs.

I don't believe we say anywhere that the collection url would fall back to the handle anywhere.

If you want the taxonomies to have the appropriate collection urls, make it so by mounting the collection.

Is there a reason you want or need to make this work without adding a mount to the collection?

@jasonvarga
Copy link
Member

jasonvarga commented Jul 19, 2024

Nevermind all that, sorry. I see that it does work in some cases without being mounted.

352772e

🤐

@jasonvarga
Copy link
Member

The only incorrect behavior I can see on the 5.x branch is that for a taxonomy with a collection, the uri will not include the collection handle when the collection doesn't have a mount.

Terms have the correct uris.

e.g.

// $blog has a mount
$blog->mount(); // Entry at /the-blog

// $articles doesnt
$articles->mount(); // null

$taxonomy->collection($blog)->uri(); // /the-blog/tags ✅
$taxonomy->collection($articles)->uri(); // /tags ❌, should be /articles/tags - this PR is fixing this.

$term->collection($blog)->uri(); // /the-blog/tags/foo ✅
$term->collection($articles)->uri(); // /articles/tags/foo ✅

Even visiting /articles/tags loads fine. It's just that if you put {{ url }} on that page, it would output /tags which is wrong.

I don't think we really need to ever bother with that new check "is assigned to collection". I think it's ok to assume that the collection you pass to the taxonomy will be one it's assigned to.

I'm happy to make the changes since I'm in here but I just wanted to make sure I'm understanding what you were trying to solve.

@aerni
Copy link
Contributor Author

aerni commented Jul 22, 2024

The reason I've used isAssignedToCollection() instead of collection() was to introduce a tighter guard in case you're interacting programmatically with a taxonomy/term. If we're only checking for collection(), you could create/edit a taxonomy/term programmatically, attach a collection to it and get a URL returned that doesn't actually exist because the taxonomy hasn't been assigned to the collection.

I also wanted to align the implementation with #10438 that also uses isAssignedToCollection().

But you're right, we could technically get away with just checking for ! $this->collection() on the taxonomy and !$this->taxonomy()->collection() on the term, instead of using isAssignedToCollection().

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