/** * Return an array of fields for a given entity - this is the same as the BAO function but * fields are prefixed with 'custom_' to represent api params */ function _civicrm_api_get_custom_fields($entity, &$params) { $customfields = array(); $entity = _civicrm_api_get_camel_name($entity); if (strtolower($entity) == 'contact') { // Use sub-type if available, otherwise stick with 'Contact' $entity = CRM_Utils_Array::value('contact_type', $params); } $retrieveOnlyParent = FALSE; // we could / should probably test for other subtypes here - e.g. activity_type_id if ($entity == 'Contact') { empty($params['contact_sub_type']); } $customfields = CRM_Core_BAO_CustomField::getFields($entity, FALSE, FALSE, CRM_Utils_Array::value('contact_sub_type', $params, FALSE), NULL, $retrieveOnlyParent, FALSE, FALSE); $ret = array(); foreach ($customfields as $key => $value) { // Regular fields have a 'name' property $value['name'] = 'custom_' . $key; $value['title'] = $value['label']; $value['type'] = _getStandardTypeFromCustomDataType($value['data_type']); $ret['custom_' . $key] = $value; } return $ret; }
/** * Return an array of fields for a given entity. * * This is the same as the BAO function but fields are prefixed with 'custom_' to represent api params. * * @param $entity * @param array $params * * @return array */ function _civicrm_api_get_custom_fields($entity, &$params) { $entity = _civicrm_api_get_camel_name($entity); if ($entity == 'Contact') { // Use sub-type if available, otherwise "NULL" to fetch from all contact types $entity = CRM_Utils_Array::value('contact_type', $params); } $customfields = CRM_Core_BAO_CustomField::getFields($entity, FALSE, FALSE, CRM_Utils_Array::value('contact_sub_type', $params), NULL, FALSE, FALSE, FALSE); $ret = array(); foreach ($customfields as $key => $value) { // Regular fields have a 'name' property $value['name'] = 'custom_' . $key; $value['title'] = $value['label']; $value['type'] = _getStandardTypeFromCustomDataType($value); $ret['custom_' . $key] = $value; } return $ret; }
/** * Return an array of fields for a given entity - this is the same as the BAO function but * fields are prefixed with 'custom_' to represent api params */ function _civicrm_api_get_custom_fields($entity, &$params) { $customfields = array(); $entity = _civicrm_api_get_camel_name($entity); if (strtolower($entity) == 'contact') { // Use sub-type if available, otherwise stick with 'Contact' $entity = CRM_Utils_Array::value('contact_type', $params); } $retrieveOnlyParent = FALSE; // we could / should probably test for other subtypes here - e.g. activity_type_id if ($entity == 'Contact') { empty($params['contact_sub_type']); } $customfields = CRM_Core_BAO_CustomField::getFields($entity, FALSE, FALSE, CRM_Utils_Array::value('contact_sub_type', $params, FALSE), NULL, $retrieveOnlyParent, FALSE, FALSE); // find out if we have any requests to resolve options $getoptions = CRM_Utils_Array::value('get_options', CRM_Utils_Array::value('options', $params)); if (!is_array($getoptions)) { $getoptions = array($getoptions); } foreach ($customfields as $key => $value) { // Regular fields have a 'name' property $value['name'] = 'custom_' . $key; $value['type'] = _getStandardTypeFromCustomDataType($value['data_type']); $customfields['custom_' . $key] = $value; if (in_array('custom_' . $key, $getoptions)) { $customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key); } unset($customfields[$key]); } return $customfields; }