Juergen Posted December 10, 2022 Share Posted December 10, 2022 Hello @all I have searched the forum and studied the PHP class files, but I cannot find a way to achieve the following one: I want to run a Hook after the pass field (a system field) is saved. It should also work with other inputfields, but in my case I need to run it especially on the pass field. To clearify: I want to run the Hook if the "Edit field: pass" page is saved. I have tried the following inside the init() function of my module: $this->addHookAfter('Fields::save', $this, 'updateBlacklist'); The appropriate method: protected function updateBlacklist(HookEvent $event): void { $field = $field->object; if ($field->name == 'pass') { $this->wire('session')->message('works'); } } But it does not work. As mentioned by @LostKobrakai at this topic, " Field::save is called when a fieldsettings should be saved", but it seems that nothing happens. Could anyone point me into the right direction? Link to comment Share on other sites More sharing options...
Jan Romero Posted December 10, 2022 Share Posted December 10, 2022 45 minutes ago, Juergen said: $this->addHookAfter('Fields::save', $this, 'updateBlacklist'); Note that you’re hooking the save() method of “Fields” object. 45 minutes ago, Juergen said: $field = $field->object; This line makes no sense. I assume you mean “$event->object”, but because you’re hooking a method of the Fields class, I would imagine that will give you the same as wire()->fields(), not the field that was saved. The saved field is the first and only argument of the save() method, so I expect this should work: $field = $event->arguments(0); Apparently, towards the end, Fields::save() also calls Fieldtype::savedField() , so you may want to hook that instead: $this->addHookAfter('FieldtypePassword::savedField', $this, 'updateBlacklist'); protected function updateBlacklist(HookEvent $event): void { $field = $events->arguments(0); if ($field->name == 'pass') { $this->wire('session')->message('works'); } } 2 Link to comment Share on other sites More sharing options...
Juergen Posted December 10, 2022 Author Share Posted December 10, 2022 Thanks @Jan Romero What a silly mistake!!! ??You are right: 1 hour ago, Jan Romero said: I assume you mean “$event->object”, Sure, that was the mistake. I know that it must be $event and not $field, but I have overlooked this silly mistake over and over and I was wondering why it did not work. I have tried it with $event->object and $event->arguments(0).... BTW: Now both Hooks work with $event->arguments(0)!! Thanks for your help!!! Thanks for helping me 1 Link to comment Share on other sites More sharing options...
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