added hook_simplenews_subscriber_delete to simplenews_mailjet_subscriptions

This commit is contained in:
Bachir Soussi Chiadmi 2022-06-16 10:38:50 +02:00
parent 5ff92a7063
commit 6f87574096
1 changed files with 23 additions and 2 deletions

View File

@ -20,7 +20,7 @@ index 2512a39..d4b0440 100644
- simplenews:simplenews - simplenews:simplenews
+ - mailjet:mailjet + - mailjet:mailjet
diff --git a/simplenews_mailjet_subscriptions.module b/simplenews_mailjet_subscriptions.module diff --git a/simplenews_mailjet_subscriptions.module b/simplenews_mailjet_subscriptions.module
index 09abe13..4b2ee58 100644 index 09abe13..a481713 100644
--- a/simplenews_mailjet_subscriptions.module --- a/simplenews_mailjet_subscriptions.module
+++ b/simplenews_mailjet_subscriptions.module +++ b/simplenews_mailjet_subscriptions.module
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
@ -54,7 +54,7 @@ index 09abe13..4b2ee58 100644
} }
/** /**
@@ -51,19 +51,19 @@ function simplenews_mailjet_subscriptions_simplenews_subscribe(Subscriber $subsc @@ -51,19 +51,40 @@ function simplenews_mailjet_subscriptions_simplenews_subscribe(Subscriber $subsc
function simplenews_mailjet_subscriptions_simplenews_unsubscribe(Subscriber $subscriber, string $subscription) { function simplenews_mailjet_subscriptions_simplenews_unsubscribe(Subscriber $subscriber, string $subscription) {
$entities = SimplenewsMailjetSubscriptionEntity::loadMultiple(); $entities = SimplenewsMailjetSubscriptionEntity::loadMultiple();
foreach ((array) $entities as $entity) { foreach ((array) $entities as $entity) {
@ -74,6 +74,27 @@ index 09abe13..4b2ee58 100644
} }
} }
+ // \Drupal::service('simplenews_mailjet_subscriptions.utilities')->unsubscribeUser($subscriber, $subscription); + // \Drupal::service('simplenews_mailjet_subscriptions.utilities')->unsubscribeUser($subscriber, $subscription);
+}
+
+/**
+ * Act after a subscriber has been deleted.
+ *
+ * @param \Drupal\simplenews\Entity\Subscriber $subscriber
+ * The subscriber object including all subscriptions of this user.
+ *
+ * @ingroup subscriber
+ */
+function simplenews_mailjet_subscriptions_simplenews_subscriber_delete(Subscriber $subscriber) {
+ $entities = SimplenewsMailjetSubscriptionEntity::loadMultiple();
+ foreach ((array) $entities as $entity) {
+ $listID = $entity->getID();
+ $table = $entity->get('mapping_table');
+ if (is_array($table)) {
+ foreach ($table as $category) {
+ \Drupal::service('simplenews_mailjet_subscriptions.utilities')->unsubscribeUser($listID, $subscriber, $category);
+ }
+ }
+ }
} }
/** /**