simplenews_mailjet_subscriptions: added rules action to respond to unsubscribe webhook

This commit is contained in:
2022-06-17 11:35:06 +02:00
parent 5c37d02cb7
commit 8ac394cff0
3 changed files with 101 additions and 13 deletions

View File

@@ -301,6 +301,62 @@ index 98342b5..f67ba96 100644
$form['add_subscription'] = [
'#type' => 'submit',
diff --git a/src/Plugin/RulesAction/UnsubscribeFromList.php b/src/Plugin/RulesAction/UnsubscribeFromList.php
new file mode 100644
index 0000000..c6a5a77
--- /dev/null
+++ b/src/Plugin/RulesAction/UnsubscribeFromList.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\simplenews_mailjet_subscriptions\Plugin\RulesAction;
+
+use Drupal\rules\Core\RulesActionBase;
+use Drupal\simplenews\SubscriberInterface;
+
+/**
+ * Provides a 'Unsubscribe' action.
+ *
+ * @RulesAction(
+ * id = "rules_simplenews_mailjet_subscriptions_unsubscribe_from_list",
+ * label = @Translation("Unsubscribe from newsletter, giving mailjet listID and email"),
+ * category = @Translation("Simplenews Mailjet Subscriptions"),
+ * context_definitions = {
+ * "listID" = @ContextDefinition("integer",
+ * label = @Translation("Mailjet list ID"),
+ * description = @Translation("Specifies the mailjet list ID from which simplenews list will be found and email will be unsubscribed from.")
+ * ),
+ * "email" = @ContextDefinition("string",
+ * label = @Translation("Subscriber email"),
+ * description = @Translation("Specifies the email to unsubscribe.")
+ * )
+ * }
+ * )
+ */
+class UnsubscribeFromList extends RulesActionBase {
+
+ /**
+ * Deletes the Entity.
+ *
+ * @param integer listID
+ * The mailjet list to unsubcsribe from.
+ *
+ * @param string email
+ * The email to unsubcribe.
+ */
+ protected function doExecute(integer $listID, string $email) {
+ $l = $listID;
+ $e = $email;
+ \Drupal::logger('simplenews_mailjet_subscriptions')->info("Unsubscribe webhook triggered for listID: " . $listID . ", and email: " . $email . ".");
+ // find corresponding simplenews list from mailjet listID
+
+ // get subscriber entity
+
+ // unsubscribe subscriber from simplenews list
+ }
+
+}
\ No newline at end of file
diff --git a/src/SimplenewsMailjetSubscriptionsInterface.php b/src/SimplenewsMailjetSubscriptionsInterface.php
index c727d26..37c082d 100644
--- a/src/SimplenewsMailjetSubscriptionsInterface.php