CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [solved] blank custom tokens
Pages: [1]

Author Topic: [solved] blank custom tokens  (Read 459 times)

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
[solved] blank custom tokens
December 15, 2013, 04:45:12 am
I'm using Drupal 7.23 and civicrm 4.4.2.

The following code lets you select the 'Primary Contact First Name & Primary Contact Last Name tokens, but these are blank with actions of Send email to contacts or Print pdf letter for contacts. The query runs fine in phpmyadmin.

function ncca_custom_civicrm_tokens(&$tokens){
  $tokens['pc'] = array(
    'pc.first_name' => 'Primary Contact First Name',
    'pc.last_name' => 'Primary Contact Last Name',
  );
}

function hook_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
  // primary_contact tokens
  if (!empty($tokens['pc'])) {
   
    $orgs = implode(',', $cids);
    $dao = &CRM_Core_DAO::executeQuery("select r.contact_id_b, c.first_name, c.last_name from civicrm_contact c
                join civicrm_relationship r on r.contact_id_a = c.id
                where r.contact_id_b in ($orgs)");
    while ($dao->fetch()) {
        $cid = $dao->contact_id_b;
        $values[$cid]['pc.first_name'] = $dao->first_name;
        $values[$cid]['pc.last_name'] = $dao->last_name;
           
    }
  }
       
}
« Last Edit: December 15, 2013, 02:21:25 pm by Coleman Watts »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: blank custom tokens
December 15, 2013, 10:29:51 am

do u need to rename: hook_civicrm_tokenValues to ncaa_custom_civicrm_tokenValues

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dlats

  • I post occasionally
  • **
  • Posts: 77
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.12
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
Re: blank custom tokens
December 15, 2013, 12:08:30 pm
That's it. I stared at that for a whole day and didn't see it.

Thanks.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [solved] blank custom tokens

This forum was archived on 2017-11-26.