Skip to content

add flexibility to Post setUrl method#506

Merged
bennothommo merged 7 commits into
rainlab:masterfrom
mjauvin:add-seturl-params
Jul 11, 2020
Merged

add flexibility to Post setUrl method#506
bennothommo merged 7 commits into
rainlab:masterfrom
mjauvin:add-seturl-params

Conversation

@mjauvin
Copy link
Copy Markdown
Contributor

@mjauvin mjauvin commented Jun 20, 2020

The blogPosts component calls each posts setUrl() method but cannot provide the currently selected category.

this PR adds a $params array to allow overriding parameters when setting the post's URL.

the PR modifies the blogPosts component by passing the current category when setting each post's url.

@LukeTowers
Copy link
Copy Markdown
Contributor

Could you provide an example of behavior that this PR now enables? It doesn't quite make sense to me.

@mjauvin
Copy link
Copy Markdown
Contributor Author

mjauvin commented Jun 20, 2020

If you have blog posts that have more than one category, the post url will be built using the first category instead of the currently selected category. So if your blogPost page has the following url, the category was always the first category:

url = "/post/:slug/:category?"

Now it property assigns the selected category.

Comment thread components/Posts.php Outdated
@bennothommo
Copy link
Copy Markdown
Contributor

@mjauvin Looks fine to me - I'll give it a test tomorrow and merge it if it's all good.

@mjauvin
Copy link
Copy Markdown
Contributor Author

mjauvin commented Jun 28, 2020

Hi @bennothommo, did you get a chance to test it?

@bennothommo
Copy link
Copy Markdown
Contributor

@mjauvin Sorry, I haven't yet. I will try to get onto it shortly.

@mjauvin
Copy link
Copy Markdown
Contributor Author

mjauvin commented Jul 6, 2020

Any luck @bennothommo?

Comment thread models/Post.php
Comment thread models/Post.php Outdated
@bennothommo
Copy link
Copy Markdown
Contributor

@mjauvin I've tested it and it works, but I'm now in two minds about allowing people to override all the parameters - the category, sure, but not so much the ID and slug. What are your thoughts on just allowing the category to be overridden through the third parameter in setUrl?

@LukeTowers
Copy link
Copy Markdown
Contributor

@bennothommo what are your concerns with the current approach?

@bennothommo
Copy link
Copy Markdown
Contributor

@LukeTowers mainly just being able to override the other params - such as id and slug. I feel they should be locked down in some way so someone doesn't inadvertently make incorrect URLs.

@LukeTowers
Copy link
Copy Markdown
Contributor

@bennothommo I feel like if they do, they're doing it on purpose. It's not like they can accidentally pass that data in, they have to be very explicit about it. I feel like it adds the greatest degree of flexibility and support for future params we may want to use without being a massive pitfall for users / developers.

@mjauvin
Copy link
Copy Markdown
Contributor Author

mjauvin commented Jul 10, 2020

Frankly, I don't personally think this is an issue but I do think adding this is supposed to help flexibility/extensibility so it IS possible to cause mayhem (as it is with many event handlers if we want to go that far)

@bennothommo
Copy link
Copy Markdown
Contributor

I can't think of a specific scenario where this could cause mayhem without it being the result of someone doing something intentionally stupid, so I'll merge it. There's just one change I'll suggest first before doing so.

Comment thread models/Post.php Outdated
Comment thread models/Post.php Outdated
@LukeTowers
Copy link
Copy Markdown
Contributor

LGTM, @bennothommo you can merge when you're happy with it.

@mjauvin mjauvin deleted the add-seturl-params branch July 11, 2020 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Completed Fix is completed and merged into the dev branch; remaining open until it has been merged into master Type: Maintenance Minor maintenance to the code base (i.e. minor bug fixes, styling fixes, translation improvements)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants