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) »
  • hook_civicrm_tokens function interferes with individual display name
Pages: [1]

Author Topic: hook_civicrm_tokens function interferes with individual display name  (Read 1054 times)

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
hook_civicrm_tokens function interferes with individual display name
January 13, 2011, 02:41:20 am
Hi there,

I'm hoping can shed some light on this;  I've just discovered a strange problem with the civicrm_tokens hook.  When I add an individual, the display isn't stored, instead, the email address is displayed in the listing.  When I removed the civicrm_tokens hook function, the problem is corrected.

This is the tokens hook function that I'm using:

Code: [Select]
function joomla_civicrm_tokens( &$tokens ) {
    $tokens['contact'] =
array('contact.testtoken' => 'another teset token',
      'contact.employer_phone' => 'employer phone',
      'contact.employer_email' => 'employer email',
      'contact.employer_address_1' => 'employer address 1',
      'contact.employer_adress_2' => 'employer address 2',
      'contact.employer_address_3' => 'employer address 3',
      'contact.employer_city' => 'employer city',
      'contact.employer_name' => 'employer name',
      'contact.province' => 'employer county',
      'contact.employer_membertype' => 'employer membership type',
      'contact.member_no' => 'membership number',
      'contact.serviceinfo' => 'services info',
      'contact.total_payable' => 'total payable',
  'contact.employee_name' => 'Employee name',
      'contact.employee_address_1' => 'Employee address 1',
      'contact.employee_adress_2' => 'Employee address 2',
      'contact.employee_address_3' => 'Employee address 3',
      'contact.employee_city' => 'Employee city',
  'contact.start_date' => 'Membership Start Date',
  'contact.statecounty' => 'State / County',
  'contact.employee_postal_code' => 'Employee Postal Code',
  'contact.employee_state_province' => 'Employee State / Province',
  'contact.individual_member_no' => 'Individual Member Number',
  'contact.indiviudal_total_fee' => 'Individual Total Fee',
  'contact.state_province_name' => 'Individual State Province Name',
  'contact.individual_membership_type' => 'Individual Membership Type'
);
}

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_tokens function interferes with individual display name
January 13, 2011, 03:57:30 am
Can you explain your use case? Why are you overwriting $tokens['contact'] ?

Kurund
Found this reply helpful? Support CiviCRM

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: hook_civicrm_tokens function interferes with individual display name
January 13, 2011, 06:25:02 am
Hi Kurund,  thanks for your reply.

The tokens are for the "print PDF letter" feature.  I don't know why I used $token['contact'] at first - but I thought it might be a problem so I replace it with $tokens['special'], and then with $tokens['xxxx'] -  and it still made so difference.  Still can't save the Individuals display name.

The function now looks like:

Code: [Select]
function joomla_civicrm_tokens( &$tokens ) {
    $tokens['xxxx'] =
array('xxxx.testtoken' => 'another teset token',
      'xxxx.employer_phone' => 'employer phone',
      'xxxx.employer_email' => 'employer email',
      'xxxx.employer_address_1' => 'employer address 1',
      'xxxx.employer_adress_2' => 'employer address 2',
      'xxxx.employer_address_3' => 'employer address 3',
      'xxxx.employer_city' => 'employer city',
      'xxxx.optional_extras' => 'optional extras',
      'xxxx.additional_children' => 'additional children',
      'xxxx.employer_name' => 'employer name',
      'xxxx.province' => 'employer county',
      'xxxx.employer_membertype' => 'employer membership type',
      'xxxx.member_no' => 'membership number',
      'xxxx.serviceinfo' => 'services info',
      'xxxx.total_payable' => 'total payable',
  'xxxx.employee_name' => 'Employee name',
      'xxxx.employee_address_1' => 'Employee address 1',
      'xxxx.employee_adress_2' => 'Employee address 2',
      'xxxx.employee_address_3' => 'Employee address 3',
      'xxxx.employee_city' => 'Employee city',
  'xxxx.start_date' => 'Membership Start Date',
  'xxxx.statecounty' => 'State / County',
  'xxxx.employee_postal_code' => 'Employee Postal Code',
  'xxxx.employee_state_province' => 'Employee State / Province',
  'xxxx.individual_member_no' => 'Individual Member Number',
  'xxxx.indiviudal_total_fee' => 'Individual Total Fee',
  'xxxx.state_province_name' => 'Individual State Province Name',
  'xxxx.individual_membership_type' => 'Individual Membership Type'
);
}

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_tokens function interferes with individual display name
January 13, 2011, 06:31:17 am
Ok will investigate and get back here.

Kurund
Found this reply helpful? Support CiviCRM

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: hook_civicrm_tokens function interferes with individual display name
January 13, 2011, 06:48:41 am
I fixed it with a workaround - though still no wiser as to what caused it - but this is what I'm using to fix the issue:

Code: [Select]
function joomla_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {

if ($op == "create" && $objectName == "Individual") {
$sql = "UPDATE civicrm_contact
SET display_name = CONCAT(first_name, ' ', last_name), sort_name = CONCAT(first_name, ' ', last_name)
WHERE id = '".$objectRef->id."'";

$dao = CRM_Core_DAO::executeQuery($sql);
}

}

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_tokens function interferes with individual display name
January 17, 2011, 01:33:12 pm
You need to use token and tokenValue hook as mentioned below

Quote
function joomla_civicrm_tokens( &$tokens ) {
    $tokens['contact'] =
   array('contact.testtoken' ,
         'contact.employer_phone' ,
         'contact.employer_email' ,
         'contact.employer_address_1'
   );
}

Quote
function joomla_civicrm_tokenValues( &$values, &$contactIDs ) {
    $values =
   array('contact.testtoken' => 'test token ',
         'contact.employer_phone' => 'Employee Phone',
         'contact.employer_email'  => ' a@b.com',
         'contact.employer_address_1' => ' test address'
   );
}

HTh

Kurund
Found this reply helpful? Support CiviCRM

simonium

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 2
Re: hook_civicrm_tokens function interferes with individual display name
January 19, 2011, 05:57:27 am
Thanks Kurund!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_tokens function interferes with individual display name

This forum was archived on 2017-11-26.