Jump to content

restrict page->viewable via hook


bernhard
 Share

Recommended Posts

hi,

i have some settings under a page called /tools (for example /tools/default-mail-data-for-events or the like). i want all pages under this parent be hidden on the frontend so i came up with this:

$this->addHookAfter('Page::viewable', $this, 'hideToolPagesFromFrontend');

/**
* hide all pages under /tools from frontend access
**/
public function hideToolPagesFromFrontend($event) {
$page = $event->object;
bd($page->closest('/tools')->path);
if($page->closest('/tools')->id) $event->return = false;
}
the tabs should look like this:

the tabs look usually like this:

post-2137-0-99645100-1464436604_thumb.pn

but when the hook is active all tabs except "content" are hidden:

post-2137-0-48267100-1464436655_thumb.pn

the dump is like this:

post-2137-0-38955100-1464436678_thumb.pn

why is page viewable called on every tab? how can i just hide the "view" tab? on frontend the functionality is as supposed...

Link to comment
Share on other sites

Not really an answer to your question, but do these pages under /tools/ have template files?

If no, they can't be viewed on the front-end.

If yes and you are using them in other pages with $mypage->render() then you can make them not directly viewable by having this at the start of the template file:

if(empty($options['pageStack'])) throw new Wire404Exception();

Apologies if this isn't helpful.

Link to comment
Share on other sites

thank you robin,

yes, they do have a template file, because its the same template i use on lots of other pages that have to be viewable on frontend. i fixed it quickly by putting this in my _main.php file:

<?php
if($page->closest('/tools')->id) throw new Wire404Exception();

pw is so awesome :)

but i would prefer to understand whats going on and why viewable is called for every tab in the page editor :)

ps: 700 posts... i'm getting old :D

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...