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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Token {contact.state_province_name} doesn't work in templates and export
Pages: [1]

Author Topic: Token {contact.state_province_name} doesn't work in templates and export  (Read 700 times)

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Token {contact.state_province_name} doesn't work in templates and export
July 11, 2011, 09:56:49 am
Hi,

Apparently the token {contact.state_province_name} is not working when is included in message templates. The text "{contact.state_province_name}" is shown and not the proper Province/State Name.
This token works only for Mailing Labels, but we need the print PDF or send email with the full Province Name

Only the token {contact.state_province} is working showing the abbreviation everywhere.
Sadly this is a very "american way" to display states, but I would say that in the rest of the world (at least SouthAmerica and mostly Europa) the full province name is needed

Any clue if it's a bug, a new feature or there is a way make this work (maybe by hooks)?

Tx in advance
 
 

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Token {contact.state_province_name} doesn't work in templates and export
September 06, 2011, 08:19:31 am
Solved with hook_civicrm_tokens && hook_civicrm_tokenValues if someona has the same problem :)

Luciano S.

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
  • iXiam Team Leader
  • CiviCRM version: 4.2+ / 4.3+ / 4.4+
  • CMS version: Drupal
  • MySQL version: 5.1+ / 5.5+
  • PHP version: 5.3+ / 5.4+
Re: Token {contact.state_province_name} doesn't work in templates and export
September 06, 2011, 08:25:34 am
I share the code if it's useful to somebody
I added two tokens:

{contact.province}: prints the State / Province full name (as in {contact.state_province_name}). I didn't use the same name in case this brings any conflict with the existing one

{contact.complete_address}: prints the full contact's address with the same format set in the label address customization



Code: [Select]
function yourmodulename_civicrm_tokens( &$tokens ) {
$tokens['contact'] = array('contact.province' => 'Province', 'contact.complete_address' => 'Complete Address' );
}


function yourmodulename_civicrm_tokenValues( &$values, &$contactIDs ) {
require_once 'api/v2/Contact.php';
require_once 'CRM/Utils/Address.php';
foreach($contactIDs as $id){
$params = array('contact_id'=>$id);
$contact = civicrm_contact_get($params);
$values[$id]['contact.complete_address'] = nl2br(CRM_Utils_Address::format($contact[$id]));
$values[$id]['contact.province'] = $contact[$id]["state_province_name"];
}
}

Cheers!
Luciano

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 {contact.state_province_name} doesn't work in templates and export
September 06, 2011, 05:37:26 pm

cool. thanx for sharing! nice example :)

a word of caution: if u r sending lots and lots of emails (100K+), the inner loop executes multiple queries per contact ID and may not be the most efficient

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) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Token {contact.state_province_name} doesn't work in templates and export

This forum was archived on 2017-11-26.