Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many of "Roles" hooks don't work #360

Closed
adrianbj opened this issue Aug 30, 2017 · 8 comments
Closed

Many of "Roles" hooks don't work #360

adrianbj opened this issue Aug 30, 2017 · 8 comments

Comments

@adrianbj
Copy link

adrianbj commented Aug 30, 2017

Short description of the issue

Most of the Roles hooks don't work

These work
Roles::deleteReady
Roles::deleted
Roles::saveReady
Roles::saved

but these don't work
Roles::add
Roles::delete
Roles::save
Roles::added

Expected behavior

They should work :)

Actual behavior

They don't work :) :)

Steps to reproduce the issue

Add this to ready.php and then create a new role.

$this->addHookBefore("Roles::added", function($event) {
    wire('log')->save('testing', 'Roles::added');
});

Nothing will appear in the log file.

This has been confirmed by others: https://processwire.com/talk/topic/17087-roles-hooks-not-working/

Setup/Environment

  • ProcessWire version: 3.0.73, 2.8.62, 2.7.3
@adrianbj
Copy link
Author

Same goes for the Permissions class actually. I haven't checked all the direct and inherited methods, but I checked "add" and it doesn't work, but "deleted" does.

@ryancramerdesign
Copy link
Member

I'm not really sure what to do about those hooks because they are of pretty limited use. I'm thinking maybe I should just remove or deprecate them. That's because in order for some of them to get called (like those you mentioned, except for added), the method call has to originate on $roles (or $permissions, etc.), and/or the Page has to actually be of a specific type, i.e. Role rather than Page as the class name. There are cases where these conditions aren't present, which means the hooks aren't reliable at catching everything for their type. Best bet is to always use the "Pages::" hooks and check for template there, plus it's more efficient to do so. For these PagesType hooks I think we'll want to deprecate them.

@adrianbj
Copy link
Author

If they are problematic then I agree they should be removed - the Pages:: versions will be just fine.

@postscript-chris
Copy link

Users::added does not work either @ryancramerdesign

@netcarver
Copy link
Collaborator

@ryancramerdesign Bumping for consideration.

ryancramerdesign added a commit to processwire/processwire that referenced this issue Mar 26, 2019
@ryancramerdesign
Copy link
Member

I had previously made these hooks deprecated. But after @netcarver 's bump, I revisited this and decided to go in the opposite direction and instead make the hooks fully functional in all situations. Rather than only being called if the class name matches what it's supposed to be, the hooks will be called if the template is one that is valid for the type. This ensures they will be called in the situations where they might not have been previously.

@netcarver
Copy link
Collaborator

Great, thanks Ryan!

@adrianbj
Copy link
Author

Awesome to have these working! I just tested a few and they seem to be working as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants