simplenews_mailjet_subscriptions: added rules action to respond to unsubscribe webhook
This commit is contained in:
		| @@ -19,13 +19,18 @@ config_version: '3' | ||||
| expression: | ||||
|   id: rules_rule | ||||
|   uuid: fb766314-f49f-4aba-9115-8c5b362cf404 | ||||
|   weight: 0 | ||||
|   conditions: | ||||
|     id: rules_and | ||||
|     uuid: 2c3970cc-c861-4c32-881d-a4683faa2541 | ||||
|     weight: 0 | ||||
|     conditions: | ||||
|       - | ||||
|         id: rules_condition | ||||
|         uuid: 2bea8cc9-4a68-40f4-822e-bf5d0f16c20f | ||||
|         weight: 0 | ||||
|         condition_id: rules_data_comparison | ||||
|         negate: false | ||||
|         context_values: | ||||
|           operation: '==' | ||||
|           value: unsub | ||||
| @@ -37,9 +42,37 @@ expression: | ||||
|           value: | ||||
|             rules_tokens: {  } | ||||
|         provides_mapping: {  } | ||||
|         condition_id: rules_data_comparison | ||||
|       - | ||||
|         id: rules_condition | ||||
|         uuid: fe051e60-fd5e-4e90-a272-c526017966cb | ||||
|         weight: 0 | ||||
|         condition_id: rules_entity_is_of_type | ||||
|         negate: false | ||||
|         context_values: | ||||
|           type: mailjet_event | ||||
|         context_mapping: | ||||
|           entity: mailjet_event | ||||
|         context_processors: | ||||
|           type: | ||||
|             rules_tokens: {  } | ||||
|         provides_mapping: {  } | ||||
|   actions: | ||||
|     id: rules_action_set | ||||
|     uuid: 5c91a286-ea41-47f7-b6a9-451cb4bb2324 | ||||
|     actions: {  } | ||||
|     weight: 0 | ||||
|     actions: | ||||
|       - | ||||
|         id: rules_action | ||||
|         uuid: 7eb49497-8830-46d4-975c-6b25b5d6dee6 | ||||
|         weight: 0 | ||||
|         action_id: rules_simplenews_mailjet_subscriptions_unsubscribe_from_list | ||||
|         context_values: | ||||
|           listID: mailjet_event.event_field.mj_list_id | ||||
|           email: mailjet_event.event_field.email | ||||
|         context_mapping: {  } | ||||
|         context_processors: | ||||
|           listID: | ||||
|             rules_tokens: {  } | ||||
|           email: | ||||
|             rules_tokens: {  } | ||||
|         provides_mapping: {  } | ||||
|   | ||||
| @@ -824,9 +824,9 @@ display: | ||||
|           entity_field: status | ||||
|           plugin_id: boolean | ||||
|           operator: '=' | ||||
|           value: All | ||||
|           value: '1' | ||||
|           group: 1 | ||||
|           exposed: false | ||||
|           exposed: true | ||||
|           expose: | ||||
|             operator_id: '' | ||||
|             label: Active | ||||
| @@ -836,23 +836,22 @@ display: | ||||
|             operator_limit_selection: false | ||||
|             operator_list: {  } | ||||
|             identifier: status | ||||
|             required: false | ||||
|             required: true | ||||
|             remember: false | ||||
|             multiple: false | ||||
|             remember_roles: | ||||
|               authenticated: authenticated | ||||
|               anonymous: '0' | ||||
|               admin: '0' | ||||
|               root: '0' | ||||
|               contact_company: '0' | ||||
|               adherent: '0' | ||||
|               free_user: '0' | ||||
|               premium: '0' | ||||
|               unverified: '0' | ||||
|               student: '0' | ||||
|               anonymous: '0' | ||||
|               free_user: '0' | ||||
|               contact_company: '0' | ||||
|               alpha_testeur: '0' | ||||
|               student: '0' | ||||
|               adherent: '0' | ||||
|               translator: '0' | ||||
|               admin_showroom: '0' | ||||
|               admin: '0' | ||||
|               root: '0' | ||||
|           is_grouped: false | ||||
|           group_info: | ||||
|             label: '' | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user