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) »
  • Can't get $job from hook_civicrm_tokenValues when doing a mailing
Pages: [1]

Author Topic: Can't get $job from hook_civicrm_tokenValues when doing a mailing  (Read 731 times)

herb

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Can't get $job from hook_civicrm_tokenValues when doing a mailing
October 28, 2012, 09:58:04 am
I have been unable to output the $job variable when doing a mailing with a custom token defined in hook_civicrm_tokenValues. I can output the other variables in the function but not $job. Does it work for others or is there a bug?

I tried it on a fresh install and still was unable to output the $job.

To test one could just run a custom module with this:

function hook_civicrm_tokens(&$tokens) {
  $tokens['test'] = array(
    'test.job' => 'Job ID',
  );
}

function hook_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
 
  CRM_Core_Error::debug('job', $job);

  if (!empty($tokens['test'])) {
    $test = array(
      'test.job' => 'job='. $job,
    );
    foreach ($cids as $cid) {
      $values[$cid] = empty($values[$cid]) ? $test : $values[$cid] + $test;
    }
  }
}
Web Developer
Freeform Solutions

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Can't get $job from hook_civicrm_tokenValues when doing a mailing
October 28, 2012, 10:03:26 am
Thanks for updating the hook docs. I updated a bit further to encourage people to use the $tokens param and to clarify that $cids is always an array (and the old if($single) construct found in some code snippets should be ignored).

I admit I've never actually used the $job param for anything. What do you need it for and what value did you expect it to contain?
Try asking your question on the new CiviCRM help site.

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: Can't get $job from hook_civicrm_tokenValues when doing a mailing
October 28, 2012, 10:22:55 am

herb:

can u please try the patch committed against that issue

thanx

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

herb

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: Can't get $job from hook_civicrm_tokenValues when doing a mailing
November 08, 2012, 02:52:44 pm
We went a slightly different direction with that client, and they were using a version lower than that which was patched. I will try to test it soon when I have a chance on another client.
Web Developer
Freeform Solutions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Can't get $job from hook_civicrm_tokenValues when doing a mailing

This forum was archived on 2017-11-26.