- π¬π§United Kingdom adamps
We have a new 4.x in alpha, so it's a good time to look at this again
- π¬π§United Kingdom adamps
We could fire the hook in postSave() with code roughly like this.
if ($this->isConfirmed() && isset($this->original) { // Compare subscriptions of new and old. $added = ... $removed = ... foreach ($added as $newsletter_id) { \Drupal::moduleHandler()->invokeAll('simplenews_subscribe', [$this, $newsletter_id]); } foreach ($removed as $newsletter_id) { \Drupal::moduleHandler()->invokeAll('simplenews_unsubscribe', [$this, $newsletter_id]); }
Does that sound good?
- Status changed to Needs review
about 1 year ago 2:39pm 24 September 2023 - last update
about 1 year ago 59 pass - last update
about 1 year ago 59 pass - πΊπΈUnited States smokris Athens, Ohio, USA
I've attached patches (based on AdamPS's snippet above) for simplenews 3.x and 4.x.
- Status changed to Needs work
about 1 year ago 7:47am 25 September 2023 - π¬π§United Kingdom adamps
Thanks @smokris
1) Actually my comment #8 wasn't quite right. I think we need like this:
if (isset($this->original) && $this->original->isConfirmed()) { $original = $this->original->getSubscribedNewsletterIds(); } else { $original = []; }
2) Let's create a variable for the current ones too so we don't calculate them twice:
$current = $this->getSubscribedNewsletterIds();
3) Plus a variable for the result of
\Drupal::moduleHandler()
so we don't calculate it many times.4) It would be great to have a test for the hooks. But if you don't want to, it's still useful to fix the other commentsπ.
- Assigned to adamps
- Status changed to Needs review
about 1 year ago 5:00pm 6 October 2023 - last update
about 1 year ago 61 pass - last update
about 1 year ago 61 pass - last update
about 1 year ago PHPLint Failed - last update
about 1 year ago 61 pass -
AdamPS β
committed 72b09ed2 on 4.x
Issue #3260907 by AdamPS, smokris: hook_simplenews_subscribe fires...
-
AdamPS β
committed 72b09ed2 on 4.x
- Status changed to Fixed
about 1 year ago 1:27pm 7 October 2023 - Issue was unassigned.
Automatically closed - issue fixed for 2 weeks with no activity.