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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Token {contact.state_province_name} not working in templates and export
Pages: [1]

Author Topic: Token {contact.state_province_name} not working in templates and export  (Read 1427 times)

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Token {contact.state_province_name} not working in templates and export
December 06, 2012, 07:50:59 am
This topic was covered previously but last added to in 2011 by user sluc23, so I thought a new topic would be better - I have exactly the same issue in that I'm in Ireland and need the 'state' to display in full on letters etc - ie Wexford not WX:

Quote
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

The solution of implementing a 'hook' with hook_civicrm_tokens and hook_civicrm_tokenValues  was given as follows:

Quote
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"];      
   }
}

but
a) I can't find info in the wiki about how to implement this under wordpress (mentions joomla and drupal only)
b) I have no problem amending code - I just can't figure out where to amend it.  ???

If someone could help that would be great.

Thank you so much!
Clare.

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} not working in templates and export
December 06, 2012, 10:01:25 am

check the docs here:

http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference#HookReference-Proceduresforimplementinghooks

someone added a brief wordpress section. would be great if you can use that and elaborate a bit more as needed

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

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Re: Token {contact.state_province_name} not working in templates and export
December 07, 2012, 02:07:31 am
Thanks - I read that but didn't see the WP bit - perhaps I missed it...

I'll look through again  ;)

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Re: Token {contact.state_province_name} not working in templates and export
December 07, 2012, 05:57:42 am
hi...

OK based on my interpretation of the wiki...

I added the custom PHP directory in admin
then created a php file called civicrmHooks.php (which was the included file in crm/utils/hook.php)

Quote
      if (!empty($config->customPHPPathDir) &&
        file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
      ) {
        @include_once ("civicrmHooks.php");
      }

which contained:

Quote
<? php

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


function wordpress_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"];     
   }
}

?>
this causes the civicrm admin to break and just show a white screen - if I remove the php file it works again.

can you tell me where I'm going wrong?  :-\

thank you!

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} not working in templates and export
December 07, 2012, 08:02:13 am

the white page indicates that you most likely have a syntax or parse error in your php file

might want to run "php -l FILENAME" from the cmd line on civicrmHooks.php and fix that file

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

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Re: Token {contact.state_province_name} not working in templates and export
December 07, 2012, 08:24:39 am
ok - I think you've lost me completely now.

 :-[

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Re: Token {contact.state_province_name} not working in templates and export
December 12, 2012, 05:53:03 am
I could really use clarification on this ... I apologise if these are stupid questions but I'm one of 2 staff working part time for a national charity and have already passed the deadline for this and had to revert to exporting all the details out to word to get the mailing out.

I wish I had hours to work through pages and pages of wiki and figure it all out myself but I dont and now am coming under pressure to just drop civi as it's taking me away from fundraising work. I know in the long run it will bring benefits but just getting basic things to work seems like a mammoth task!

I am tech savvy but feel all the documentation assumes you already know your way around the inner working of civi. I can change and tweak code but find getting info on or getting someone to point me in the right direction of WHERE to make changes impossible

 ???

again i'm sorry for stupid questions but I've always search the wiki and forums first before I ask...

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} not working in templates and export
December 12, 2012, 08:58:33 am

I cut and pasted your code and created a file called: /tmp/tt.php

then from the command line i ran:

$ php -l /tmp/tt.php

It gave me an error on line 3 and then i noticed u had a space between <? and php. it should be: <?php

fixing that fixed the file (and hence most likely will fix your white screen

While many of us are willing to help and push you in the right direction, we do assume a pretty good knowledge of php and mysql if you are going to customize civi from the backend

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

theclaredotcom

  • I’m new here
  • *
  • Posts: 26
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: wordpress 3.4
  • MySQL version: 5.5.16
  • PHP version: 5.3.8
Re: Token {contact.state_province_name} not working in templates and export
December 12, 2012, 12:18:29 pm
Hi Donald,

I do have good sql (being a qualified developer) and reasonable php, but when you've been spending hours going through the forums and wiki for solutions  you get a bit a code blind - and knowing code doesn't help when there's not a lot of info about file structure - which is where I keep hitting issues.

So I'm not asking for someone to do the work for me and I want to learn -  but there's tons of pages of writing the hooks themselves, but I spent literally hours trying to find out WHERE to add the hook php, what it needed to be called  etc - a paragraph at the beginning of the section before going into the detail of the code would have saved me so much wasted time - this is whats causing me most frustration.

 :-\
Thank you for taking the time tho to look at the issue - i do appreciate it
C.

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} not working in templates and export
December 12, 2012, 01:58:51 pm

We are trying to centralize all developer documentation in:

1. The book: http://book.civicrm.org/developer/

2. http://wiki.civicrm.org/confluence/display/CRMDOC42/Developer+Reference

There is a paragraph at the beginning for all 3 CMS's on how to do  write a hook etc. Developers from different CMS'es need to contribute back and help make the docs better and more full featured (if it is lacking)

Would be great if you can spend some time using your learnings and help improve the documentation / layout so folks down the road can benefit

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 »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Token {contact.state_province_name} not working in templates and export

This forum was archived on 2017-11-26.