3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * CiviCRM APIv3 pseudoconstants
16 * The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.
17 * @package CiviCRM_APIv3
21 * Declare deprecated api entity.
23 * @deprecated api notice
25 * to indicate this entire api entity is deprecated
27 function _civicrm_api3_constant_deprecation() {
28 return 'The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.';
32 * Get constant values (deprecated).
34 * @deprecated as of CiviCRM 4.4.
35 * It's recommended to use the api getoptions action instead
37 * @param array $params
38 * Name of a public static method of
39 * CRM_Core_PseudoConstant: one of
64 * paymentProcessorType
71 * stateProvinceAbbreviation
72 * stateProvinceForCountry
83 function civicrm_api3_constant_get($params) {
85 $name = $params['name'];
86 // all the stuff about classes should be adequately replaced by the bit in the 'else'
87 //ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
88 // once tests are 100% can try removing the first block & a similar block from Generic:getoptions
90 // Whitelist approach is safer
92 'CRM_Core_PseudoConstant',
93 'CRM_Event_PseudoConstant',
94 'CRM_Contribute_PseudoConstant',
95 'CRM_Member_PseudoConstant',
97 $className = $allowedClasses[0];
98 if (!empty($params['class']) && in_array($params['class'], $allowedClasses)) {
99 $className = $params['class'];
101 $callable = "$className::$name";
102 if (is_callable($callable)) {
103 if (empty($params)) {
104 $values = call_user_func([$className, $name]);
107 $values = call_user_func([$className, $name]);
108 //@TODO XAV take out the param the COOKIE, Entity, Action and so there are only the "real param" in it
109 //$values = call_user_func_array( array( $className, $name ), $params );
111 return civicrm_api3_create_success($values, $params, 'Constant');
114 $values = call_user_func(['CRM_Utils_PseudoConstant', 'getConstant'], $name);
115 if (!empty($values)) {
116 return civicrm_api3_create_success($values, $params, 'Constant');
119 return civicrm_api3_create_error('Unknown civicrm constant or method not callable');
123 * Adjust metadata for constant get action.
125 * @param array $params
127 function _civicrm_api3_constant_get_spec(&$params) {
153 'paymentProcessorType',
160 'stateProvinceAbbreviation',
161 'stateProvinceForCountry',
172 'title' => 'Constant Name',
175 'options' => array_combine($options, $options),
176 'type' => CRM_Utils_Type
::T_STRING
,