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) »
  • Custom tokens in mailing labels stopped working in ver. 4.1.1.
Pages: [1] 2

Author Topic: Custom tokens in mailing labels stopped working in ver. 4.1.1.  (Read 3055 times)

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
Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 12:58:00 pm
I have a module that implements the hook "mymodule_civicrm_tokenValues( &$values, &$contactIDs ) "

Two of the new tokens created by my hook are "contact.joint_greeting_casual" and "joint_greeting_casual" 

Prior to the upgrade from 3.4.7 to 4.1.1, I was able to use the token "contact.joint_greeting_casual" in mailing labels.    But after the upgrade, this token stopped working on the labels. Yet they will work as expected in emails, and "Create PDF Letter"

What do I need to change in the hook for mailing labels for 4.1.1.?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 01:43:47 pm
Sarah - I know there was quite a lot of re-write - have you checked the blog on this?
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

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 tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 01:57:18 pm

probably a bug :( If you can track and fix it that would be great

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

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 02:09:04 pm
What  file/class should I start debugging?
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 03:24:45 pm
I have started debugging the file "CRM/Contact/Form/Task/Label.php" around line 212. 

My hook IS getting called, but for reasons I do not understand the values are not getting placed onto the label.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 03:31:07 pm
So, after your hook the values ARE changed? Has the token format changed? I haven't looked at the 4.1 changes enough to understand what they mean for integration code.
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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 03:51:44 pm
I added the following to the Civi code:

  $tokens = array( );
        CRM_Utils_Hook::tokens( $tokens );
        print "<hr><br><h2>Test from labels</h2><br>";
        print_r($details[0]);


( The first 2 lines were already there)

This lists all the values that I am expecting from my custom tokens.
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 06:03:41 pm
I created an issue at: http://issues.civicrm.org/jira/browse/CRM-9901 to track the progress of this bug
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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 20, 2012, 07:52:20 pm

Would be great if you can continue debugging and tracking the code to figure out where the bug is occuring. If you need help or get stuck, u can ping us on IRC. We definitely do encourage consultants and integrators to take the next step and help fix the issues they file.

this will ensure it gets fixed in the next point release

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

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 05:44:47 pm
I have made some progress in my debugging, need some additional input.

I put some debug code just above the line:
 
           
Code: [Select]
$formatted = CRM_Utils_Address::format( $row, 'mailing_format', false, true, $individualFormat, $tokenFields );   
The value for $row includes standard fields like display_name, plus all my custom tokens.   

The value for $tokenFields is:  Array (
  • => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 [37] => 37 [38] => 38 [39] => 39 [40] => 40 [41] => 41 [42] => 42 [43] => 43 [44] => 44 [45] => 45 [46] => 46 [47] => 47 [48] => 48 [49] => 49 [50] => 50 [51] => 51 [52] => 52 [53] => 53 [54] => 54 [55] => 55 [56] => 56 [57] => 57 [58] => 58 [59] => 59 [60] => 60 [61] => 61 [62] => 62 [63] => 63 [64] => 64 [65] => 65 [66] => 66 [67] => 67 [68] => 68 [69] => 69 [70] => 70 [71] => 71 [72] => 72 [73] => 73 [74] => 74 [75] => 75 [76] => 76 [77] => 77 )


However, the return value "$formatted" does NOT include my custom token.    Where is the source code file for the class "CRM_Utils_Address" ?  I would like to debug that as well.

Thanks,
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 06:02:09 pm
It should be 'CRM/Utils/Address.php'
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

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 tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 06:08:45 pm

the value for tokenFields seems wrong, way wrong :(

I think it should be an array of the tokens that are used. i'll need to check

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

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 06:13:59 pm
I added the following debugging code within "sites/all/modules/civicrm/CRM/Utils/Address.php"  at the start of the "format" function:

print "<br>format: ".$formatted;
   print "<br>fields: ";
   print_r($fields);
   print "<br><br>tokenFields: ";
   print_r($tokenFields);

The results I get are:


format: {contact.joint_greeting_casual} {contact.street_address} {contact.supplemental_address_1} {contact.supplemental_address_2} {contact.city}{, }{contact.state_province}{ }{contact.postal_code} {contact.country}

fields: Array ( [contact_type] => Individual [display_name] => Josh Cohen [do_not_mail] => 0 [is_deceased] => 0 [address_id] => 17 [street_address] => 1 S. Wacker [city] => Chicago [postal_code] => 60606 [state_province_id] => 1012 [state_province_name] => Illinois [state_province] => IL [country_id] => 1228 [country] => United States [contact.joint_greeting_casual] => Josh Cohen [joint_greeting_casual] => Josh Cohen [contact.joint_greeting_formal] => Mr. Cohen [joint_greeting_formal] => Mr. Cohen [contact.joint_greeting_formal_firstname] => Mr. Josh Cohen [joint_greeting_formal_firstname] => Mr. Josh Cohen  )

tokenFields: Array (
  • => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 [15] => 15 [16] => 16 [17] => 17 [18] => 18 [19] => 19 [20] => 20 [21] => 21 [22] => 22 [23] => 23 [24] => 24 [25] => 25 [26] => 26 [27] => 27 [28] => 28 [29] => 29 [30] => 30 [31] => 31 [32] => 32 [33] => 33 [34] => 34 [35] => 35 [36] => 36 [37] => 37 [38] => 38 [39] => 39 [40] => 40 [41] => 41 [42] => 42 [43] => 43 [44] => 44 [45] => 45 [46] => 46 [47] => 47 [48] => 48 [49] => 49 [50] => 50 [51] => 51 [52] => 52 [53] => 53 [54] => 54 [55] => 55 [56] => 56 [57] => 57 [58] => 58 [59] => 59 [60] => 60 [61] => 61 [62] => 62 [63] => 63 [64] => 64 [65] => 65 [66] => 66 [67] => 67 [68] => 68 [69] => 69 [70] => 70 [71] => 71 [72] => 72 [73] => 73 [74] => 74 [75] => 75 [76] => 76 [77] => 77 )




Then at the end of this function, I added:
 print "<br>Final Formatted: ".$finalFormatted;

The output is:
Final Formatted: 1 S. Wacker Chicago, IL 60606 United States
« Last Edit: March 21, 2012, 06:15:45 pm by Sarah Gladstone »
Did I help you? Please donate to the Civi-Make-It-Happen campaign  CiviCRM for mobile devices! 

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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 06:45:55 pm
I found and fixed the bug!

Its in file "sites/all/modules/civicrm/CRM/Contact/Form/Task/Label.php" in function "postProcess"

The original code was:
Code: [Select]
$tokenFields = array( );
        foreach ( $tokens as $category => $catTokens ) {
            foreach ( $catTokens as $token => $tokenName ) {
                $tokenFields[] = $token;
            }
        }


The working code is:

Code: [Select]
$tokenFields = array( );
        foreach ( $tokens as $category => $catTokens ) {
            foreach ( $catTokens as $token ) {
                $tokenFields[] = $token;
            }
        }
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: Custom tokens in mailing labels stopped working in ver. 4.1.1.
March 21, 2012, 06:49:13 pm
I suspect something has changed in the $tokens format. I would add some debug statements and find out why $tokenFields is so wierd. If you have a 3.4 or 4.0 install, i would compare it to that version

Cool, and congrats on finding the fixing the issue. Much appreciated :) Now wondering what happened and why it worked in 3.4/4.0?

Can you print the $tokens array from your install

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] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Custom tokens in mailing labels stopped working in ver. 4.1.1.

This forum was archived on 2017-11-26.