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) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Custom hook tokens not working in CiviMail
Pages: [1] 2

Author Topic: Custom hook tokens not working in CiviMail  (Read 4344 times)

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Custom hook tokens not working in CiviMail
April 05, 2012, 03:56:25 am
Hi,

I have recently upgraded a site to CiviCRM 4.1.1 running on Drupal 6. However, after the upgrade, I'm having problems with some of the tokens defined in my hook_civicrm_tokens and hook_civicrm_tokenValues functions. The tokens are correctly replaced when sending an email from the actions menu in CiviCRM core, and are correctly processed when creating a PDF letter. However, when I send using CiviMail, the recipient gets a message that includes '{contact.birth_date_dmy}' rather than '16/12/1975'.

I can see that my hook_civicrm_tokenValues function does indeed get called when I send via CiviMail, but the custom tokens are not replaced. I thought that maybe my hook_civicrm_tokenValues function had a bug, but now I see that the tokens seem to work fine everywhere except for CiviMail.

Has anyone else had this problem? Could this be a bug in CiviMail in 4.1.1? Or might there be some other problem that I've missed?

Cheers,
-Ian




jimurl

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 0
  • CiviCRM version: 3.4.6
  • CMS version: drupal 6.22
  • MySQL version: 5+
  • PHP version: 5+
Re: Custom hook tokens not working in CiviMail
April 05, 2012, 03:58:16 pm
I can verify that this also occurs on Civi 3.4.6 / D6. 24 . I know that it did use to work on a very slightly earlier version - either 3.4.4 or 3.4.5 .

Wait:
Quote
CiviCRM 4.1.1 running on Drupal 6
? Are you sure you don't mean D7?

Like you, I found the hooks do appear to get called in the preview pane; but not when the email is actually sent.

I am happy to help troubleshoot this, if a higher-up can show us where to start, Ian.

jim

andrewhunt

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 13
    • AGH Strategies
  • CiviCRM version: all of 'em
  • CMS version: Drupal, Joomla, and WordPress
Re: Custom hook tokens not working in CiviMail
April 05, 2012, 05:44:56 pm
I've also noticed some inconsistent behavior in custom tokens when they appear in other situations (PDF letters, labels, and as part of greetings), so it would be worth double-checking those in the process of fixing and testing it for CiviMail.  It looks like fixing an issue caused this bug, and it has been reopened:
http://issues.civicrm.org/jira/browse/CRM-8989
You can find me at AGH Strategies.
Need help now?  Civi911 is your go-to for CiviCRM support.

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Re: Custom hook tokens not working in CiviMail
April 08, 2012, 03:53:00 am
Hi all,

Jim-

CiviCRM 4.1.1 is distributed with different tarballs for Drupal 6 and Drupal 7, just like there's a different version packaged for Joomla.

I can see that my hook_civicrm_tokenValues function gets called when I send a test email or a final mailing, but the tokens never get replaced.

Andrew-

Thanks for flagging up that issue. However, the patch in that issue relates to tokens in mailing labels, and changes to 'CRM/Contact/Form/Task/Label.php'. The issue I'm having is with token replacement for CiviMail email sending. In fact, my custom tokens do indeed work fine when generating mailing labels. But the same tokens don't work with CiviMail.

-Ian




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: Custom hook tokens not working in CiviMail
April 08, 2012, 07:15:34 am

i did a quick test of this on my svn version. I've not had time to investigate what is happening but my results were:

1. custom tokens do not work but regular tokens work on civimail test mailing

2. both custom tokens and regular tokens work on the actual civimail mailings

can u check and test that u see if u get the same results

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

jimurl

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 0
  • CiviCRM version: 3.4.6
  • CMS version: drupal 6.22
  • MySQL version: 5+
  • PHP version: 5+
Re: Custom hook tokens not working in CiviMail
April 11, 2012, 03:40:09 pm
Hello,

I was incorrect before, standard tokens ARE being replaced by the _civicrm_tokenValues hook. ( As an aside, I was trying to replace contact.nick_name token with contact.first_name if nick.name was missing. But I didn't have contact.first_name as a token in my email body anywhere! So it must not have been passed to the hook function.)

Custom field tokens were also replaced properly. So this is what ended up in the final email, as it should be:

Code: [Select]
first name: Jimsfirstname
nick name: jimshort
custom: data entry date: April 1st, 2012
HS or MS : High School

This occurred for both test mailing and the final mailing.
So, I don't think this is an issue for CiviCRM 3.4.6 ; perhaps only on 4.1.x

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Re: Custom hook tokens not working in CiviMail
April 11, 2012, 04:13:49 pm
Hi,

After a bunch of testing with 4.1.1, I found that the $tokens parameter from hook_civicrm_tokenValues looks like
Code: [Select]
$tokens = array('category' => array('token_name' => 1)) when called from CiviMail, but seems to be
Code: [Select]
$tokens = array('category' => array('token_name')) when called from other places.

Also, I can't seem to get {contact.*} tokens defined within hook_civicrm_tokenValues to work at all from CiviMail, whereas they seem to work from PDF and core email functions.

I haven't had time to do any conclusive testing with an svn trunk version. Is it possible to check out 4.1.1 for D6 from SVN? I couldn't find any obvious branch or tag for it.

-Ian

Masked Marauder

  • I post occasionally
  • **
  • Posts: 30
  • Karma: 1
  • \__^..^
  • CiviCRM version: 4.5.5
  • CMS version: drupal-6.34
  • MySQL version: 5.5.40-36
  • PHP version: 5.4.34
Re: Custom hook tokens not working in CiviMail
April 13, 2012, 01:41:53 pm
I'm seeing this too.

A quick question, what's the distinction between regular tokens and custom tokens?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Custom hook tokens not working in CiviMail
April 14, 2012, 04:14:10 pm
Custom tokens are defined by you when you implement hook_civicrm_tokens().
See http://civicrm.org/blogs/colemanw/create-your-own-tokens-fun-and-profit
Whoever wrote that awesome blog article deserves lots of karma points  ;)
Try asking your question on the new CiviCRM help site.

Galieth

  • I’m new here
  • *
  • Posts: 3
  • Karma: 1
  • CiviCRM version: 4.1.1
  • CMS version: J 2.5.4
  • MySQL version: 5.1.61
  • PHP version: 5.3.3-7
Re: Custom hook tokens not working in CiviMail
April 18, 2012, 11:55:00 am
In Joomla 2.5 and civic 4.1.1

I am seeing the reverse of what Lobo has above.

My custom tokens work perfectly when I do a test mailing to a group.
My custom Tokens do not work (and the hook isn't being called, I put in log code when it is hit) when I schedule a mailing.


clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Re: Custom hook tokens not working in CiviMail
July 11, 2012, 07:28:40 am
I´m exactly having the same problem as described on the initial post. I´m runnning CiviCRM 4.1.1 on Drupal 6. Have been using custom tokens for a while for Printing PDF Letter without any problem.

Now we wanted to start using them for mailings by using CiviMail. I was almost sure it will work since I made some test mailings and was working fine. However, after the mailing was sent, the custom tokens were not replaced (just empty).

I´m not sure how to resolve this problem. I could help if someone points me in the right direction.

Regards,


Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Custom hook tokens not working in CiviMail
July 11, 2012, 08:03:46 am
Why would you want to use 4.1.1 when 4.1.3 is out and contains fixes for bugs such as this?
Update: now 4.1.5
« Last Edit: July 11, 2012, 08:21:52 am by Coleman Watts »
Try asking your question on the new CiviCRM help site.

clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Re: Custom hook tokens not working in CiviMail
July 12, 2012, 03:56:59 am
I didn´t know that this bug is fixed on recent versions. I´ll try the update to 4.1.5 then to see if it works.

Thanks

clemenbor

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
  • CiviCRM version: 4.1.5
  • CMS version: Drupal 6
  • MySQL version: 5.1.48
  • PHP version: 5.2.1
Re: Custom hook tokens not working in CiviMail
October 15, 2012, 08:51:23 am
We just update to the version 4.1.5 on Drupal 6 and the problem is still there, custom tokens are working when testing a mailing, but it does not work when it is finally sent.

Also, we tried the same version 4.1.5 for Drupal 7 and is working as expected.

Does someone has an idea how to fix this on the version for Drupal 6??

Thanks in advance!

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Re: Custom hook tokens not working in CiviMail
October 16, 2012, 04:07:01 am
I have tested this is 4.2.2 with Drupal 7, and it seems like custom field tokens all work as they should on that site.

However, I maintain another site which is running 4.1.5 with Drupal 6, and I can confirm that custom field tokens are very broken on that site, which is causing lots of problems. I'm hoping to try upgrading that site to CiviCRM 4.2.2/Drupal 6, I hope that will fix the issues with custom field tokens.

-Ian

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Custom hook tokens not working in CiviMail

This forum was archived on 2017-11-26.