/** * {@inheritdoc} */ public function endpoint($hash) { $return = 0; if (!empty($_POST)) { $data = $_POST['data']; $type = $_POST['type']; switch ($type) { case 'unsubscribe': case 'profile': case 'cleaned': mailchimp_get_memberinfo($data['list_id'], $data['email'], TRUE); break; case 'upemail': mailchimp_cache_clear_member($data['list_id'], $data['old_email']); mailchimp_get_memberinfo($data['list_id'], $data['new_email'], TRUE); break; case 'campaign': mailchimp_cache_clear_list_activity($data['list_id']); mailchimp_cache_clear_campaign($data['id']); break; } // Allow other modules to act on a webhook. \Drupal::moduleHandler()->invokeAll('mailchimp_process_webhook', array($type, $data)); // Log event. \Drupal::logger('mailchimp')->info('Webhook type {type} has been processed.', array('type' => $type)); $return = 1; } // TODO: There should be a better way of doing this. // D8 routing doesn't seem to allow us to return a single character // or string from a controller. echo $return; exit; }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { $elements = array(); /* @var $item \Drupal\mailchimp_lists\Plugin\Field\FieldType\MailchimpListsSubscription */ foreach ($items as $delta => $item) { $elements[$delta] = array(); $field_settings = $this->getFieldSettings(); $mc_list = mailchimp_get_list($field_settings['mc_list_id']); $email = mailchimp_lists_load_email($item, $item->getEntity(), FALSE); if ($email) { if (mailchimp_is_subscribed($field_settings['mc_list_id'], $email)) { $status = t('Subscribed to %list', array('%list' => $mc_list['name'])); } else { $status = t('Not subscribed to %list', array('%list' => $mc_list['name'])); } } else { $status = t('Invalid email configuration.'); } $elements[$delta]['status'] = array('#markup' => $status, '#description' => t('@mc_list_description', array('@mc_list_description' => $item->getFieldDefinition()->getDescription()))); if ($field_settings['show_interest_groups'] && $this->getSetting('show_interest_groups')) { $memberinfo = mailchimp_get_memberinfo($field_settings['mc_list_id'], $email); if (isset($memberinfo['merges']['GROUPINGS'])) { $elements[$delta]['interest_groups'] = array('#type' => 'fieldset', '#title' => t('Interest Groups'), '#weight' => 100); foreach ($memberinfo['merges']['GROUPINGS'] as $grouping) { $items = array(); foreach ($grouping['groups'] as $interest) { if ($interest['interested']) { $items[] = $interest['name']; } } if (count($items)) { $elements[$delta]['interest_groups'][$grouping['id']] = array('#title' => $grouping['name'], '#theme' => 'item_list', '#items' => $items, '#type' => 'ul'); } } } } } return $elements; }
/** * Tests unsubscribing a member from a list. */ public function testUnsubscribe() { $list_id = DrupalMailchimpLists::TEST_LIST_A; $email = '*****@*****.**'; $subscribed = mailchimp_subscribe($list_id, $email); $this->assertTrue($subscribed, 'Tested new user subscription.'); $unsubscribed = mailchimp_unsubscribe($list_id, $email); $this->assertTrue($unsubscribed, 'Tested user unsubscription.'); $member_info = mailchimp_get_memberinfo($list_id, $email); $this->assertEqual($member_info['status'], 'unsubscribed', 'Tested updated subscription state.'); // Reset subscription. mailchimp_subscribe($list_id, $email); // Delete member. mailchimp_unsubscribe($list_id, $email, TRUE); $member_info = mailchimp_get_memberinfo($list_id, $email); $this->assertTrue(empty($member_info), 'Tested user deletion on unsubscribe.'); }