You are here

function mailchimp_campaign_process_callback in Mailchimp 7.3

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_process_callback()
  2. 7.2 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_process_callback()
  3. 7.4 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_process_callback()

Callback for preg_replace in mailchimp_campaign_filter_campaign_process().

1 string reference to 'mailchimp_campaign_process_callback'
mailchimp_campaign_filter_campaign_process in modules/mailchimp_campaign/mailchimp_campaign.module
Process callback for mailchimp_campaign_filter_info().

File

modules/mailchimp_campaign/mailchimp_campaign.module, line 671
Module file for mailchimp_campaign.

Code

function mailchimp_campaign_process_callback($matches = array()) {
  $content = '';
  $entity_type = $entity_id = $view_mode = '';
  foreach ($matches as $key => $match) {
    switch ($key) {
      case 1:
        $entity_type = $match;
        break;
      case 2:
        $entity_id = $match;
        break;
      case 3:
        $view_mode = $match;
        break;
    }
  }
  $entities = entity_load($entity_type, array(
    $entity_id,
  ));
  if (!empty($entities)) {

    // Prevent session information from being rendered.
    drupal_save_session(FALSE);

    // Force the current user to anonymous to prevent access bypass.
    $original_user = $GLOBALS['user'];
    $GLOBALS['user'] = drupal_anonymous_user();

    // Render the entity.
    $render_array = entity_view($entity_type, $entities, $view_mode, NULL, TRUE);

    // Remove contextual links.
    _mailchimp_campaign_recursive_unset($render_array[$entity_type][$entity_id], '#contextual_links');
    $content = render($render_array);

    // Restore the user.
    $GLOBALS['user'] = $original_user;
    drupal_save_session(TRUE);
  }
  return $content;
}