From d04a6df3ccea9e27504e0859713bcfe711e4aaae Mon Sep 17 00:00:00 2001
Message-Id: <d04a6df3ccea9e27504e0859713bcfe711e4aaae.1362644331.git.dmitriy.trt@gmail.com>
From: "Dmitriy.trt" <dmitriy.trt@gmail.com>
Date: Thu, 7 Mar 2013 15:18:45 +0700
Subject: [PATCH] Issue #1936000: introduce
 hook_mailchimp_lists_merge_vars_alter()

---
 mailchimp.api.php |   14 ++++++++++++++
 mailchimp.module  |   14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/mailchimp.api.php b/mailchimp.api.php
index 37f4d87..5549ff8 100644
--- a/mailchimp.api.php
+++ b/mailchimp.api.php
@@ -74,3 +74,17 @@ function hook_mailchimp_lists_merge_values($mergevars, $account, $list) {
 
   return $values;
 }
+
+/**
+ * Alters merge vars before email address is subscribed or updated.
+ *
+ * @param $merge_vars
+ * @param $context
+ *   Keys:
+ *   - op: operation, "subscribe" or "update".
+ *   - email: email address that will be passed to the API call.
+ *   - list: Mailchimp list.
+ */
+function hook_mailchimp_lists_merge_vars_alter(&$merge_vars, $context) {
+  $merge_vars['MYSPECIALVAR'] = 'value';
+}
diff --git a/mailchimp.module b/mailchimp.module
index 9990881..b8f5c49 100644
--- a/mailchimp.module
+++ b/mailchimp.module
@@ -92,6 +92,13 @@ function mailchimp_is_subscribed($list_id, $email) {
  * Subscribe a user to a given list.
  */
 function mailchimp_subscribe_user($list, $email, $merge_vars, $message = TRUE, $mcapi = NULL) {
+  $context = array(
+    'op' => 'subscribe',
+    'list' => $list,
+    'email' => $email
+  );
+  drupal_alter('mailchimp_lists_merge_vars', $merge_vars, $context);
+
   $success = FALSE;
   if ($mcapi || $mcapi = mailchimp_get_api_object()) {
     $double_optin = $list->settings['doublein'];
@@ -131,6 +138,13 @@ function mailchimp_subscribe_user($list, $email, $merge_vars, $message = TRUE, $
  * Update a user in a given list.
  */
 function mailchimp_update_user($list, $email, $merge_vars, $message = TRUE, $mcapi = NULL) {
+  $context = array(
+    'op' => 'update',
+    'list' => $list,
+    'email' => $email
+  );
+  drupal_alter('mailchimp_lists_merge_vars', $merge_vars, $context);
+
   $success = FALSE;
   if ($mcapi || $mcapi = mailchimp_get_api_object()) {
 
-- 
1.7.10.4

