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_custom doesn't support is_multiple
Pages: [1]

Author Topic: hook_civicrm_custom doesn't support is_multiple  (Read 424 times)

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
hook_civicrm_custom doesn't support is_multiple
September 14, 2014, 01:53:16 am
When using custom data with checkbox fields and calling the checkbox hook, I found that what was being returned in the params was a concatenation of the values of the field. So if options included work and resident, ticking both meant that "workresident" was returned.

I couldn't find a mention of this in JIRA. Is this a known issue, and are there any workarounds (other than by doing an API call, which feels a tad hacky).

Thanks!
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: hook_civicrm_custom doesn't support is_multiple
September 14, 2014, 11:19:41 am
I'm not claiming this IS what's happening - but I know that the default "separation character" (defined in civicrm.settings.php I believe) is HEX 0x01, which is a non-printable control character.  So it's often the case that when viewing the output, there's actually a separation character, but it's not printed, so it looks like there's none.  So it may be possible that hook_civicrm_custom is returning multiple values that must be explode()'d by HEX 0x01? 
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: hook_civicrm_custom doesn't support is_multiple
September 14, 2014, 11:24:51 am
There's a pair of helper functions -- CRM_Utils_Array::explodePadded($string) and CRM_Utils_Array::implodePadded($array) -- which will convert between the delimited-string (with hex 0x01) and an array.

JohnFF

  • I post frequently
  • ***
  • Posts: 235
  • Karma: 6
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.28
  • MySQL version: 5.5.31-1
  • PHP version: 5.3.27
Re: hook_civicrm_custom doesn't support is_multiple
September 14, 2014, 04:12:09 pm
Thanks for the responses guys!

Totten esp, those functions just saved my contract :D
If you like empowering charities in a free and open way, then you're going to love Civi.

Email Amender: https://civicrm.org/extensions/email-amender
UK Phone Validator: https://civicrm.org/extensions/uk-phone-number-validator
http://civifirst.com
https://twitter.com/civifirst

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: hook_civicrm_custom doesn't support is_multiple
September 20, 2014, 05:36:42 pm
Yea and IMO those functions should never even exist (or not as public functions that anyone would ever need to use). If our DAO had been a bit more forward-thinking when it was written the developer would never have to deal with the method of serialization and would simply see arrays coming to and from the DAO (and therefore the api).

This is something I seriously want to have happen for our next api and our next generation DAO (aka Doctrine).
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_custom doesn't support is_multiple

This forum was archived on 2017-11-26.