Jump to content
wumbo

Hooking ProcessPageView

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. 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you very much!

I thought, I tried this. But I never refreshed the modules cache, I guess.

Share this post


Link to post
Share on other sites

Moved this topic the Module/Plugin Development subforum. Module development questions belong here.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lmwt
      Hi there,
      I am new to PW but already very convinced. I need to build a dropdown button to browse in a collection of authors by country and language. The dropdown should be editable in the BACK and displayed on the same as the authors collection. I tried my luck with "PageField Creator" but I don't know how to display the dropdown, I simply used: 
      "$content .=$page->Land;" (the name of the select field)
      but nothing is displayed...
      I see there is a 2nd module out there to achieve this : "Select Options Fieldtype". I am not sure what is the difference, anyone has a tip?
      And a clear tutorial with the necessary steps to build this? I am a bit confused which should be the parent template or page, if it should have a file or not...
      Thanks a lot in advance!
    • By Hardoman
      Hello community,
      we have a website running version 3.0.118. The owner would like to have a watermark merged to the images, that are being uploaded in the CKEditor as a requirement.
      Image upload besides the CKEditor within galleries and single images works as a charm already. We also use croppable image 3 there. (PIM2)
      To realize this requirement, I thought of using a hook in the admin area. So, I read a lot in our forums and tested this by adding a hook into the ready.php file.
      $this->addHookAfter('InputfieldFile::fileAdded',function(HookEvent$event){ wire('log')->save('test','Image upload works'); ... The log entry is being created correctly. But when I try to use the pim/watermark-function like in a template, he cannot find the watermark-image anymore. Furthermore, when I try to get the page-id, it does not seem to be accessible, because the application does not seem to know how to reference it, or I dont know the right way to do so…
      So my questions are:
       
      Is this the right attempt at all or will there be another, better workaround? It seems, I cannot access the page object (of the content page) within this scope or file but I would need it to save the processed image inside the right files/id folder Would it be better to place the hook into the admin-template? (or admin.php)
        Thanks for any hints in advance. 🙂
    • By martind
      hi,
      is it possible to change field parent_id from InputfieldPageListSelect to InputfieldPageAutocomplet by addHookAfter('ProcessPageEdit::buildFormContent')?
      thanks,
      martin
       
    • By Noel Boss
      👋 PW Pros…
      I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am?
      Right now, I use the following method inside one of my modules:
      public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
×
×
  • Create New...