Jump to content

lenno

Members
  • Posts

    13
  • Joined

  • Last visited

Community Answers

  1. lenno's post in Make pages accessible depending on sub-domain was marked as the answer   
    Thanks for the answer Nicolas,
    maybe i should have added some more information:
    Users will usually be guests, but it should also work for users which are logged in in the future.
    The third module you posted looks pretty similar to what I am doing right now, it also hooks into Page::viewable. This works perfectly when accessing a page, resulting in a 404 (which is fine), but the page is still listed when doing e.g. $homepage->children() or $homepage->find(). I want the page to dissapear just as for a user who does not have view permissions.
    I tried another hook:
    $this->addHookBefore('ProcessPageList::find', $this, 'checkPage'); but it does never seem to be called. I am probably doing something wrong here 
    Edit:
    Just tried something else:
    public function init() { $this->addHookBefore('Pages::find', $this, 'checkPage'); } public function checkPage($event) { $event->arguments(0, $event->arguments(0) . ", page_restricted=2"); } So I tried to extend the selector for pages to always add 'page_restricted=2' at the end. But it gives me the following error:
    Error: Exception: You do not have permission to execute this module - ProcessPageView (in [...]\wire\core\Modules.php line 1022) #0 [...]\wire\core\Modules.php(940): Modules->getModule('ProcessPageView') #1 [...]\index.php(233): Modules->get('ProcessPageView') #2 {main} This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I think I am doing something terribly wrong here. 
    Edit2:
    Well, I found a solution that seems to work:
    public function init() { $this->addHookAfter('Pages::find', $this, 'checkPage'); } public function checkPage($event) { $url = $_SERVER["HTTP_HOST"]; $isProbes = strpos($url,'probes') !== false; $pages = $event->return; foreach ($pages as $page) { $x = $page->page_restricted; if ($x) { if (($x->id === 2 && $isProbes) || ($x->id === 3 && !$isProbes)) { $pages->remove($page) ; } } } } If anyone has a better idea how to solve it, I would be glad to hear it. 
×
×
  • Create New...