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) »
  • Has civicrm_api('constant','get', $params); changed?
Pages: [1]

Author Topic: Has civicrm_api('constant','get', $params); changed?  (Read 659 times)

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Has civicrm_api('constant','get', $params); changed?
January 17, 2014, 08:08:56 am
I use to be able to so this:

         $params = array(
            'name'      => 'locationType',
            'version'   => 3
         );

         $j2c_system_location_types = civicrm_api('constant','get', $params);


To get location type values.

However, with latest civicrm 4.4.3 I am getting an error code returned:
Unknown civicrm constant or method not callable
« Last Edit: January 17, 2014, 08:25:06 am by nant »
--
Nick (aka nant from CB Team)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Has civicrm_api('constant','get', $params); changed?
January 17, 2014, 09:48:32 am
Yes, the constant api is deprecated in 4.3 and probably broken in 4.4. See https://wiki.civicrm.org/confluence/display/CRMDOC/API+changes#APIchanges-4.3.0:DeprecateConstantAPI
Try asking your question on the new CiviCRM help site.

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Re: Has civicrm_api('constant','get', $params); changed?
January 17, 2014, 03:08:05 pm
Quote from: Coleman Watts on January 17, 2014, 09:48:32 am
Yes, the constant api is deprecated in 4.3 and probably broken in 4.4. See https://wiki.civicrm.org/confluence/display/CRMDOC/API+changes#APIchanges-4.3.0:DeprecateConstantAPI

thanks for info.

now how can i figure out what the pseudoconstant name usage is for locationType ?
--
Nick (aka nant from CB Team)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Has civicrm_api('constant','get', $params); changed?
January 17, 2014, 03:22:56 pm
Did you click the documentation link?
In a nutshell we are moving away from hardcoded references to pseudoconstant names in our code. Now you can just ask the api for the option list associated with any field and it will give it to you. No more having to know magic names like "pcm" or "individual_prefix".
Try asking your question on the new CiviCRM help site.

nant

  • I post frequently
  • ***
  • Posts: 143
  • Karma: 4
    • Joomlapolis
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5.11
  • MySQL version: 5
  • PHP version: 5.3
Re: Has civicrm_api('constant','get', $params); changed?
January 17, 2014, 03:49:25 pm
Quote from: Coleman Watts on January 17, 2014, 03:22:56 pm
Did you click the documentation link?
In a nutshell we are moving away from hardcoded references to pseudoconstant names in our code. Now you can just ask the api for the option list associated with any field and it will give it to you. No more having to know magic names like "pcm" or "individual_prefix".

yup, i did click and i did read the wiki. that is how i found the term pseudoconstant.

the single example makes reference to a gender_id field and the following code:

civicrm_api3('contact', 'getoptions', array('field' => 'gender_id'));

so first not so clear conclusion is that if i use _api3 instead of _api, i don't need to add a version => 3 element in the params array.

would love to see were this is mentioned in the wiki :-)

second not so clear conclusion is that the first var in the api function call (as in the example case 'contact') refers to a civicrm database table (the contact table) and the gender_id is a column name in this table that references a field that gets option values.

with this conclusion I was able to come up with the following code to replace the depreciated function call usage:

         $params = array(
            'field'      => 'location_type_id',
            'version'   => 3
         );
         $j2c_system_location_types = civicrm_api('address', 'getoptions', $params);

or even

         $params = array(
            'field'      => 'location_type_id',
            'version'   => 3
         );
         $j2c_system_location_types = civicrm_api('email', 'getoptions', $params);

Maybe you can point me to some documentation that would make this clearer for others not that familiar with civi development and api and if not maybe i can help improve the existing references for others.

Thanks again for your response.
--
Nick (aka nant from CB Team)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Has civicrm_api('constant','get', $params); changed?

This forum was archived on 2017-11-26.