2

I have hunted and not found anything so I am assuming that this does not exist -- but thought I'd ask just in case. I'd like to be able to reference the soft credit / honoree information in Thank You letters but can't find this as a token.

I guess it's tricky to do this as a token since it relates to a specific contribution and not the contact in general. What is the best way to try to do this?

3

Here's an attempt to address this with a token that can be used with Fuzion's CiviToken extension. With that extension installed, this token file can be added to a tokens directory in your custom PHP folder to provide a "Latest Contrib Soft Credit Name" token. (It checks the latest contribution and if there is a soft credit adds the name(s) in this token). The caveat being that it only checks the latest contribution and won't work for previous contributions.

https://github.com/laryn/nz.co.fuzion.civitoken/blob/master/tokens/latestcontribs.inc

File: tokens/latestcontribs.inc

<?php

function latestcontribs_civitoken_declare($token){
  return array(
    $token . '.softcredit_name' => 'Latest Contrib Soft Credit Name',
  );
}


function latestcontribs_civitoken_get($cid, &$value, $context){
  $params = array(
    'sequential' => 1,
    'contact_id' => $cid,
    'options' => array('sort' => "receive_date DESC", 'limit' => 1),
  );
  $softcredit_formatted = "";

  $softcredit_name = civicrm_api3('Contribution', 'getsingle', $params);

  if (isset($softcredit_name['soft_credit'])) {
    $connector = "";
    $i = 0;
    $total = count($softcredit_name['soft_credit']);
    foreach($softcredit_name['soft_credit'] as $softcredit) {
      $i++;
      $softcredit_formatted .= $connector.$softcredit['contact_name'];
      if ($i == ($total-1) ) {
        $connector = " and ";
      } else {
        $connector = ", ";
      }
    }
  }
  $value['latestcontribs.softcredit_name'] = $softcredit_formatted;
  return $value;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.