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) »
  • Adding options to a custom field via API?
Pages: [1]

Author Topic: Adding options to a custom field via API?  (Read 927 times)

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
Adding options to a custom field via API?
March 12, 2011, 08:02:26 am
Hi, I'm working on my first Civi project, and most things are going pretty smoothly - I am very impressed with the UI, hooks available, and especially the views integration.

One thing I'm trying to do that I haven't figured out yet. I need my events to basically reference a drupal node of a certain type. I've created a custom field with integer values, and am manually adding the node titles as select option labels, with the node id as the value. This is working great in terms of linking the events to nodes and being able to filter them correctly in a view.

Now, what I'd like to do is add an API call in drupal that adds an option to my field if a new node is created. So I would add a hook that runs every time I create a node, which would add the node title/nid pair to my custom option list.

It looks like in the 1.x days there was a function for this, crm_create_option_value(), but I don't see an equivalent in the current API. Is this possible?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding options to a custom field via API?
March 12, 2011, 12:04:00 pm
We have OptionValue GET in the api v3 but it looks like porting Option Value Create would be a good plan

http://svn.civicrm.org/civicrm/trunk/api/v3/OptionValue.php

We do have custom field create

http://svn.civicrm.org/civicrm/trunk/api/v3/examples/CustomFieldCreate.php

NB to backport api v3 you just need to copy the api.php file & v3 folder.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

dafeder

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6
  • MySQL version: 5.092
  • PHP version: 5.2
Re: Adding options to a custom field via API?
March 12, 2011, 12:47:07 pm
Thanks! I'm sorry though, I don't quite understand your instructions for backporting, could you be a little more specific? This is something I can do by copying code from an older version of CiviCRM?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Adding options to a custom field via API?
March 12, 2011, 12:58:30 pm
The v3 api is part of the latest release. However, it should work on earlier versions if you copy the v3 files into you CiviCRM code base. I am currently doing this on a 3.3.5 site but would attempt it on any site I am doing customisation on from now on. Code it here

http://svn.civicrm.org/civicrm/trunk/api/

Or if you download & extract the latest Alpha it will be in there
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Adding options to a custom field via API?

This forum was archived on 2017-11-26.