Currently the only way for an external module to react on subscribe/unsubscribe events is to declare actions and configure them to trigger on subscribe/unsubscribe events (via simplenews_actions module).
It'll be easier and more code efficient if Simplenews defines a hook in simplenews_subscribe_user and simplenews_unsubscribe_user functions. This way custom code can be fired directly without declaring actions.
This is one line fix, but extremely important in order to allow more interaction with external modules. Patch for DRUPAL-6--2 included as attachment.
Please review and comment.
Comments
Comment #1
dankh commentedComment #2
simon georges commentedI'm affecting this to myself, so I think about reviewing it.
Code looks clean & simple enough.
Comment #3
simon georges commentedTypo in the title ;)
Comment #4
simon georges commentedOk, I've looked at your patch :
Comment #5
dankh commentedNo because the action triggers get fired only if Simplenews Actions module is installed. The invoke hook is independent of Simplenews Actions.
Comment #6
simon georges commentedOk, I see.
@miro_dietiker, @Sutharsan, do you see something preventing this addition (a matter of performance, maybe, or something else I'd be missing) ?
Comment #7
simon georges commentedCommitted to 6.x-2.x.
Let's see if someone complains ;-)
Comment #8
simon georges commentedComment #9
pillarsdotnet commentedPatch for 7.x-1.x
Comment #10
simon georges commentedCommitted.
Comment #12
jonhattanWondering if it's too late to complain :)
The implementation in D6 is unusable: there's no info about the subscription passed through to the hooks. Attached patch mimics the same behaviour as in D7. It also takes care of #4.
btw, actions integration is broken in the same way, although it is not my battle and I've also heard that actions are gone in D7 version in favour of rules.
Comment #13
berdirIt's never to late to complain if you provide a patch :)
Changes look good to me. The variable rename is unfortunate, but probably necessary. FYI, simplenews_get_subscription() is gone in 7.x in favor of simplenews_subscriber_load_*() functions (they're not entities though, but that will most likely happen for 7.x-2.x)
Yes, actions integration is gone in 7.x and I'm not sad about that ;)
Comment #14
jonhattanYes, I did read 7.x before proceeding with this patch. The variable rename is in concordance with 7.x. It is unfortunate, but isolated in the involved functions.
Is the test bot stalled or just tests for simplenews that doesn't fire?
Comment #15
jonhattanThere're some failures with this patch
Comment #16
berdirThere are more than just some failures without this patch as well :)
The 6.x tests are completely broken, that's why the testbot postpones testing of your patch until those tests are fixed. Unless you can manually confirm that there are *more* test failures with your patch than without, you can safely ignore them.
I once started backporting the current 7.x-1.x tests to 6.x-2.x but it's quite a bit of work. If you're interested in that, ping me and I can give you what I came up with.
Comment #17
jonhattanHere is a better patch.
I'm not excited about working on tests by now, but I will continue posting patches as bugs hit me.
Comment #18
jonhattanA bug related to this patch found. Confirmation link was bad.
Prehaps I need those tests though. Berdir, please expose those tests to me by the mean you consider more convenient.. mail, issue, git branch...
Comment #19
berdirThe backport of the tests is now available in #1532122: Backport of the 7.x-1.x tests, your patch should automatically be picked up by the testbot once they are commited and the branch tests pass.
Comment #20
jonhattantest passes. I'll try to provide a test to cover this hooks.
Comment #21
thijsvdanker commentedPatch in #18 makes perfect sense, and passes the simpletest.. ready for commit?
Comment #22
rmcom commentedsupporting commit of this patch
Comment #23
rmcom commentedHas this patch ever been rolled into the D6 version?