You are here

function mailchimp_mergevars_populate in Mailchimp 7.3

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_mergevars_populate()
  2. 7.4 mailchimp.module \mailchimp_mergevars_populate()

Replace an array of merge field placeholder tokens with their values.

Parameters

array $mergefields: An array of merge fields and token place holders to be expanded. The key of the array is the MailChimp field name, the value is the token that should be expanded.

object $entity: The entity that contains the values to use for token replacement.

string $entity_type: The entity type of the entity being used.

Return value

mixed Associative array of MailChimp fields with values taken from the provided entity.

2 calls to mailchimp_mergevars_populate()
_mailchimp_lists_mergevars_populate in modules/mailchimp_lists/mailchimp_lists.module
Helper function to complete a MailChimp-API-ready mergevars array.
_mailchimp_lists_subscription_has_changed in modules/mailchimp_lists/mailchimp_lists.module
Helper function to avoid sending superfluous updates to MailChimp.

File

./mailchimp.module, line 1461
Mailchimp module.

Code

function mailchimp_mergevars_populate($mergefields, $entity, $entity_type) {
  $mergevars = drupal_static(__FUNCTION__, array());
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  if (!isset($mergevars[$bundle . ':' . $id])) {
    foreach ($mergefields as $key => $token) {
      $mergevars[$bundle . ':' . $id][$key] = token_replace($token, array(
        $entity_type => $entity,
      ), array(
        'clear' => TRUE,
      ));
    }
  }
  return $mergevars[$bundle . ':' . $id];
}