Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am proposing (and currently coding a patch for) a hook in this module which fires when push_notifications_store_token is called. I think we want to offer two possibilities here:
- Allow the hook to return a value of false which would stop execution before the token is written to the database.
- Allow the hook to modify the values passed in to it. (e.g. token, type_id, uid)
Code to follow.
(As a related note, we may consider adding one which fires when a push is done. It would be nice to allow programmers to hook into both of these events.)
Comment | File | Size | Author |
---|---|---|---|
#4 | 1705990-hook-push-notifications-store-token.patch | 1.61 KB | webkenny |
Comments
Comment #1
webkenny CreditAttribution: webkenny commentedOriginal thoughts. Seems modifying only the token is probably the best idea right now. Another implementation may need to add a lot of lines to convert the 3 variables into an array and then back out again. If we think it'll be useful, I'll do so. In the meantime, thinking of rolling this patch. Feedback welcome:
If they decide to set $token to false, it will not write anything. Could be useful for doing additional access checks not covered by the module itself. (e.g. is the user part of a group)
Comment #2
haagendazs CreditAttribution: haagendazs commentedHi webkenny,
Great idea to add a hook that allows other modules to modify the token if they need to. My suggestion for adding the hook would be changing the name to 'push_notifications_store_token' and change it as following:
This way, other modules could implement the hook and pass the token by reference, for example
What do you think?
Comment #3
haagendazs CreditAttribution: haagendazs commentedSmall change: I noticed that you probably need the type_id and uid in the hook. With that in mind, the change should probably be:
Other modules could then use it like this:
Comment #4
webkenny CreditAttribution: webkenny commentedExcellent! I was, in fact, hoping to pass all 3 but only have to modify token if needed. Beautifully done. :) Patch attached. I also added an api.php file to document the hook and any future ones we may consider.
Comment #5
haagendazs CreditAttribution: haagendazs commentedThanks for the patch file and the additional api.php file. I applied the patch to the 7.x-1.x branch here: http://drupalcode.org/project/push_notifications.git/commit/f0d7e7b4ce1d....