Jump to content

Can't hook in my modules......


hellomoto
 Share

Recommended Posts

I was working on this:

class PWCRM extends WireData implements Module {
  public static function getModuleInfo() {
          return array(
                  'title' => 'Client Relationship Management',
                  'version' => .001,
                  'singular' => true,
                  'autoload' => true
          );
  }

  public function init() {}

  public function ready() {
    $this->pages->addHookBefore('render', $this, 'accessHook');
    $this->pages->addHookAfter('render', $this, 'hookAfterPageRender');
  }

  public function accessHook(HookEvent $event) {
    $page = $this->wire('page');
    if (!strpos($page->template->tags, 'crm')) return;
    if (!$this->wire('user')->hasRole('crm')) $this->wire('session')->redirect($this->wire('config')->urls->login);//throw new Wire404Exception();
  }

  public function hookAfterPageRender(HookEvent $event) {
    $page = $event->object;
    echo $page->template->tags;
    if (!strpos($page->template->tags, 'crm')) return;
    echo $this->wire('config')->urls->templates;
    include_once($this->wire('config')->urls->templates.'functions.inc');
    $pagehtml = $event->return;
    $pagehtml = str_replace(
      '</head>',
      '<link id="css_crm" rel="stylesheet" href="'.$this->wire('config')->urls->templates.'css/crm.css">
      </head>',
	  $pagehtml
	);
    $event->return = $pagehtml;
    //$event->replace = true;
  }
}

I have tried placing the hooks into the init() function, and more... Neither method is effective. The echoes now output, but no redirection (although I have the access settings for the top-level template for this set to render a 404 for underprivileged users, which it does, overriding this, but nonetheless this should work aside from that.

Then I wrote this up quick:

<?php namespace ProcessWire;

class MaintenanceMode extends WireData implements Module {
  public static function getModuleInfo() {
    return array(
        'title' => 'Maintenance Mode',
        'version' => 1,
        'summary' => 'Disables the website frontend for non-superusers.',
        'singular' => true,
        'autoload' => true,
        'permanent' => false
    );
  }

  public function init() {
    $this->addHookBefore('Page::render', $this, 'displayDecide');
  }

  public function displayDecide($event) {
    $page = $event->object;
    if ($page->template == 'admin' || $this->wire('user')->hasRole('superuser')) return;
    // replace the method hooked
    $event->replace = true;
    $event->return = "Patience please while we undergo some brief maintenance work.";
  }

}

which likewise avails nothing. What the hell is my problem here????:'(:angry: 

Link to comment
Share on other sites

All good sorry I'm burnt out. Please grant me the ability to delete my own posts, for the sake of us all, and I promise to be more careful hereon anyhow.

  public function hookAfterPageRender($event) {
    $page = $event->object;
    if (strpos($page->template->tags, 'crm') === false) return;
    $event->return = str_replace(
      '</head>',
      enqueuess(['crm' => $this->wire('config')->urls->templates.'css/crm.css']).'</head>',
      $event->return
    );
  }

 

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

×
×
  • Create New...