Closed oliverschneider closed 7 years ago
Shouldn't be the following extension be enough?
/**
* Check whether the page is accessible by the current user.
*
* @param \Page $page Page to test.
* @param \User|\Role $obj User or role object.
* @return bool
*/
$kirby->set('page::method', 'isAccessibleByCurrentUser', function($page) {
return $page->isAccessibleBy($page->site()->user());
});
I will test the suggested method and will add the corresponding extensions for File
, Files
and Pages
as well.
The new release provides the desired page methods.
Thank you, works as expected 👍 .
To get only the user accessible pages for the menu (in template files) with easy chaining like so
I created another function for the pages object, that works directly with the current user role. As there is no role for a not logged in user and Kirby returns false if you ask for the user, I had to temporarily create one. In my code, I even created an extension for Kirby $site object with a function $site->userRole() that does lines 48-55 and returns role wether there is a logged in user or not.