Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow $page()->addable() to be called with a template or template name #294

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
Loading
from

Conversation

JanRomero
Copy link
Contributor

Currently it seems awkward to check if a user is allowed to create a page of a specific template under a specific parent. It seems one is supposed to do this?

if (page()->addable(pages()->newPage('comment')))
    echo "<a href='/newcomment/?parent={$page->id}'>Add comment</a>";

Maybe there is an easier way that I’m unaware of. This proposal would simplify the API to:

if (page()->addable('comment'))

Which I find quite legible. I must admit I don’t fully understand all implications of this change because I got lost in User::hasPermission(), where the argument eventually ends up in multi-language environments. It’s possible to call User::hasPermission() with a template as well as a page, so it won’t throw, but it takes different branches my feeble mind can’t follow.


I noticed that page()->addable() may return true if the argument is invalid or doesn’t exist. Is this by design? My first code block would return true if there was no template called 'comment'. I’ve added a comment with a suggestion that would return false instead.

Thank you!

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.

1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.