You are here

function campaignmonitor_subscribe in Campaign Monitor 8

Subscribe a user to a CampaignMonitor list in real time or by adding to the queue.

See also

CampaignMonitor_Lists::subscribe()

5 calls to campaignmonitor_subscribe()
CampaignMonitorIcsForm::submitForm in modules/campaignmonitor_ics/src/Form/CampaignMonitorIcsForm.php
Form submission handler.
CampaignMonitorSubscribeForm::submitForm in src/Form/CampaignMonitorSubscribeForm.php
Form submission handler.
CampaignMonitorUserSubscriptionForm::submitForm in modules/campaignmonitor_user/src/Form/CampaignMonitorUserSubscriptionForm.php
Form submission handler.
campaignmonitor_registration_form_user_register_submit in modules/campaignmonitor_registration/campaignmonitor_registration.module
Submission form handler. Information about the selected list will be submitted to Campaign Monitor.
campaignmonitor_registration_hold_user_update in modules/campaignmonitor_registration_hold/campaignmonitor_registration_hold.module
Implements hook_ENTITY_TYPE_update().

File

./campaignmonitor.module, line 316
Module that plugs in Campaign Monitor functionality to your Drupal web site. For Campaign Monitor information see: http://www.campaignmonitor.com/.

Code

function campaignmonitor_subscribe($list_id, $email, $name, $merge_vars = NULL, $interests = [], $double_optin = FALSE, $format = 'html', $sanitize_custom = TRUE) {

  // Load the user object.
  $current_user = \Drupal::currentUser();
  $account = User::load($current_user
    ->id());
  $settings = campaignmonitor_get_list_settings($list_id);
  if (isset($settings['display']['name_field']) && is_string($settings['display']['name_field']) && $settings['display']['name_field'] != '') {
    $value = $account
      ->get($settings['display']['name_field'])
      ->getValue();
    if (isset($value[0]['value']) && $value[0]['value'] != '') {
      $name = $account
        ->get($settings['display']['name_field'])
        ->getValue()[0]['value'];
    }
  }
  $config = \Drupal::config('campaignmonitor.settings');
  if ($config
    ->get('cron')) {
    $args = [
      'list_id' => $list_id,
      'email' => $email,
      'merge_vars' => $merge_vars,
      'interests' => $interests,
      'double_optin' => $double_optin,
      'format' => $format,
    ];
    return campaignmonitor_addto_queue('campaignmonitor_subscribe_process', $args);
  }
  return campaignmonitor_subscribe_process($list_id, $email, $name, $merge_vars, $interests, $double_optin, $format, $sanitize_custom);
}