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) »
  • Removing tokens from 'Insert tokens' popup
Pages: [1]

Author Topic: Removing tokens from 'Insert tokens' popup  (Read 536 times)

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Removing tokens from 'Insert tokens' popup
May 28, 2013, 02:44:12 am
Hi,

I am trying to suppress the display of some tokens on the Email composition and PDF letter composition screens when someone clicks on the 'Insert tokens' link. This is because some database fields are not used by this client, and so their inclusion in the list of tokens just creates confusion.

I'm using hook_civicrm_buildForm to try and remove some of the tokens from the list (I know this code, at the moment, would remove almost all tokens from the list. This is just to test...):
Code: [Select]
if ($formName == 'CRM_Contact_Form_Task_Email') {
  $hackfields = array('token1', 'token2', 'token3');
  foreach ($hackfields as $hackfield) {
    if ($form->elementExists($hackfield)) {
      $tokenElement =& $form->getElement($hackfield);
      $options =& $tokenElement->_options;
      // retain $options[0], unset the rest
      $options_count = count($options);
      for ($i = 1; $i < $options_count; $i++) {
        unset($options[$i]);
      }
    }
  }
}

I can see the form element's options array, and I can see that my code (which is based on the suggestions above) does unset the options correctly. However, I still get the full list of tokens when the 'Insert tokens' pop-up appears. Is there something else I have to do? Or maybe modifying the CRM_Contact_Form_Task_Email form is not the correct way of removing tokens from the pop-up list? I haven't yet actually found the CiviCRM code that produces that list of available tokens, so I was hoping the buildForm hack would do it. But I don't think it will.

I'm familiar with using hook_civicrm_tokens and hook_civicrm_tokenValues to add new tokens to the system, but I don't think those hooks can be used to remove built-in tokens. Or can they? Any pointers would be much appreciated.

Many thanks,
-Ian

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Removing tokens from 'Insert tokens' popup

This forum was archived on 2017-11-26.