netcarver Posted August 14, 2021 Posted August 14, 2021 Hello wonderful PW-philes, I have a situation where I'd like to prevent system notifications from being stored when a self-registered user logs in or out (or fails to log in.) These events just clutter up the systemUser's notification list so I thought I'd add a hook early in the hook chain that works out if it's a self-registered user logging in and then just remove the System Notification module's hook by using removeHook(). Sure enough, I can find the target hook in the hooks returned by the system - and seemingly remove it from the hooks array - but the hook is still executed no matter how I call removeHook(). Here's the things I've tried in my hi-priority session::login hook that don't work... $id = $this->findSystemNotificationLoginHook(); $event->removeHook($id); $this->removeHook($id); parent::removeHook($id); $this->session->removeHook($id); wire()->session->removeHook($id); I've also tried targetting the actual instance by attaching to wire()->session->addHookAfter('login'...) as well - and tried doing addHookBefore(). I'm guessing that it's actually too late to remove the hook when I make the call as the hook array associated with this event is already being processed by PW and it's working its way through a local copy of the event's hooks. Does anyone have a way of removing a later hook from an event-in-progress? I can't just cancel the event as there may be other, lower priority hooks on the session::login event that I'm targetting.
horst Posted August 14, 2021 Posted August 14, 2021 Is it possible for the hook you want to skip to add a line of code that checks your conditions and act according to it? I mean, not to interact with the hook chain from within other hooks but acting within the system notification hook: if self registered user login stop logging, else proceed as default. 1
netcarver Posted August 14, 2021 Author Posted August 14, 2021 Hi @horst, thanks for the reply, but unfortunately not. I have found a work-around that I can use for now by hooking the login register pro login-form processing which happens before the session::login hook gets called, and removing it there does work. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now