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) »
  • Getting the id of a value of a custom data field within a hook
Pages: [1]

Author Topic: Getting the id of a value of a custom data field within a hook  (Read 890 times)

muppel

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: CiviCRM 3.4.4
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.56
  • PHP version: 5.3.6
Getting the id of a value of a custom data field within a hook
March 14, 2011, 01:03:18 am
I have a custom data field set with a custom data field, which I want to display within the vertical tab “Contact Details”. I do this with hook_buildForm as follows:

   switch($formName){
      case 'CRM_Contact_Form_Contact':
         $key = 'custom_16_-1';
         $form->addElement('text', $key, t('Department'), array('size' => 30));
         $defaults['custom_16_-1'] = 'DefaultValue';
         $form->setDefaults($defaults);

My question: the key ‘custom_16_-1’ works with an empty custom data field. How can I get the id of the value of the custom data field (from the civicrm_value_customdatafieldset table) within the function hook_buildForm, which I need to build the proper key for an existing value of the custom data field (i. e.  ‘custom_16_77’)?

Many thanks for your support!

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Getting the id of a value of a custom data field within a hook
March 14, 2011, 03:47:15 am
Quote from: muppel on March 14, 2011, 01:03:18 am

My question: the key ‘custom_16_-1’ works with an empty custom data field. How can I get the id of the value of the custom data field (from the civicrm_value_customdatafieldset table) within the function hook_buildForm, which I need to build the proper key for an existing value of the custom data field (i. e.  ‘custom_16_77’)?

What I do is
1) loop through the fields to see if one starts with "custom_16_"
2) and grumble about not having an id that is constant, but not too loud because lobo is going to patchwelcome me.

Seriously don't think there is an helper function yet that you can use, but would be great to have a method of form using the real name, not custom_xxx (as set in dao-field)... Patch welcome ;)

X+



-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: Getting the id of a value of a custom data field within a hook
March 14, 2011, 08:31:24 am

i like the phrase, patchwelcome :) we should get this into the official english lexicon :P

CRM_Core_BAO_CustomField::getKeyID

returns the two ids of the custom field if it is a custom field

and then u can use the fieldID to do other stuff

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

muppel

  • I’m new here
  • *
  • Posts: 22
  • Karma: 0
  • CiviCRM version: CiviCRM 3.4.4
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.56
  • PHP version: 5.3.6
Re: Getting the id of a value of a custom data field within a hook
March 15, 2011, 03:18:06 am
Many thanks Donald, that's what I was looking for.

As a newbee I am a little bit "lost in documentation" - but now I also found your advice in the  hook documentation ...

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Getting the id of a value of a custom data field within a hook

This forum was archived on 2017-11-26.