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) »
  • token hook: how do you know when to calculate?
Pages: [1]

Author Topic: token hook: how do you know when to calculate?  (Read 942 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
token hook: how do you know when to calculate?
March 01, 2011, 10:59:13 pm
Hi,

The hook to calculate the values of custom token has two params:
an array of contacts
and array of contacts id

1) What is the purpose of the second param, as the array of contacts already uses the id as the key, and has a contact_id as well?

2) How do you know what token are in the mail?
ie. I wouldn't want to fire lots of complicated requests for my complicated token if it isn't used. For what I've tested, it is called everytime, even if the token isn't in the mail.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: token hook: how do you know when to calculate?
March 01, 2011, 11:01:29 pm
erm subscribing ... both things I have wondered about. I did see something in the code that suggested they aren't always called in all circumstances but I didn't get a real grip on it.

I had thought to publish a module with a sort of pluggable token system but never got there & haven't been hassled about tokens lately...
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

SarahG (FountainTribe)

  • Ask me questions
  • ****
  • Posts: 782
  • Karma: 29
  • CiviCRM version: 4.4.7
  • CMS version: Drupal 6, Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: token hook: how do you know when to calculate?
March 02, 2011, 07:55:42 am
I have noticed the same issue with the custom tokens.  I have some custom tokens that are expensive to calculate, and it would be great if they were not calculated needlessly.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: token hook: how do you know when to calculate?
March 02, 2011, 08:13:23 am

1. sending the contactIDs is redundant. I think we sent it to the hook, because we had it lying around and were using it in the queries

2. would be good to send the list of tokens (if any) used in that mail (as an optional 4th parameter). Anyone want to take a look and contribute a patch. U'll need to fix all the place where we call

CRM_Utils_Hook::tokenValues

You can get the tokens for a mailing object using:

$mailing->getTokens( );

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • token hook: how do you know when to calculate?

This forum was archived on 2017-11-26.