Jump to content

Hooking ProcessPageView


wumbo
 Share

Recommended Posts

Hi there!

I'm using ProcessWire 3 and I'd like to build a module that tabs into the ProcessPageView::execute hook.
Currently I've built a small module that defines the hooking in its init() method as usual.

public static function getModuleInfo()
{
    return [
	    'title' => 'MicrositeRouting',
        'version' => 001,
        'summary' => 'Routing logic for microsites',
        'requires' => 'ProcessWire>=3.0.14',
        'autoload' => 'template!=admin',
        'singular' => true
    ];
}

public function init()
{
    $this->wire('log')->message(__METHOD__);
    $this->addHookBefore('ProcessPageView::execute', $this, 'lookUpPage');        
}

public function lookUpPage(HookEvent $event)
{
    $this->wire('log')->message(__METHOD__);
}

I provided some log messages to check if the module works. But it seems that in spite of the module being initialized properly (the message is found in my logs), the hook itself isn't processed at all (the log doesn't show the corresponding message).

I surely missed something important but currently can't find it.

Thank you for any suggestions. 

Link to comment
Share on other sites

I think the issue lies with the autoload condition:

9 hours ago, wumbo said:

'autoload' => 'template!=admin',

If this is changed to...

'autoload' => true,

...then it works for me. If you change this, do a refresh in Modules to clear the cache.

  • Like 2
Link to comment
Share on other sites

  • 1 month later...
  • 3 years later...

For the sake of completeness. Hooks in ProcessPageView are also possible if the hook is placed in the /site/init.php file.

Example:

// pick up $_GET['it'] (requested uri) before unset
wire()->addHookBefore('ProcessPageView::execute', function($e) {
    var_dump($_GET['it']);
});

 

  • 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

×
×
  • Create New...