The contact get "group_id" option seems to have no effect, so I removed it.
return CRM_Contact_BAO_ContactType::getSelectElements();
}
break;
+
+ // The contact api supports some related entities so we'll honor that by fetching their options
+ case 'group_id':
+ case 'group':
+ return CRM_Contact_BAO_GroupContact::buildOptions('group_id', $context, $props);
+
+ case 'tag_id':
+ case 'tag':
+ $props['entity_table'] = 'civicrm_contact';
+ return CRM_Core_BAO_EntityTag::buildOptions('tag_id', $context, $props);
+
}
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
public static function buildOptions($fieldName, $context = NULL, $props = array()) {
$params = array();
- $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+ if ($fieldName == 'tag' || $fieldName == 'tag_id') {
+ if (!empty($props['entity_table'])) {
+ $entity = CRM_Utils_Type::escape($props['entity_table'], 'String');
+ $params[] = "used_for LIKE '%$entity%'";
+ }
- // Output tag list as nested hierarchy
- // TODO: This will only work when api.entity is "entity_tag". What about others?
- if (($fieldName == 'tag' || $fieldName == 'tag_id') && ($context == 'search' || $context == 'create')) {
- $options = CRM_Core_BAO_Tag::getTags('civicrm_contact', CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+ // Output tag list as nested hierarchy
+ // TODO: This will only work when api.entity is "entity_tag". What about others?
+ if ($context == 'search' || $context == 'create') {
+ return CRM_Core_BAO_Tag::getTags(CRM_Utils_Array::value('entity_table', $props, 'civicrm_contact'), CRM_Core_DAO::$_nullArray, CRM_Utils_Array::value('parent_id', $params), '- ');
+ }
}
+ $options = CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+
return $options;
}
'title' => 'Primary Instant Messenger ID',
'type' => CRM_Utils_Type::T_INT,
);
- $params['group_id'] = array(
- 'title' => 'Group Memberships (filter)',
- );
$params['group'] = array(
- 'title' => 'Group Memberships (filter, array)',
+ 'title' => 'Group',
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_group',
+ ),
);
$params['tag'] = array(
- 'title' => 'Assigned tags (filter, array)',
+ 'title' => 'Tags',
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_tag',
+ ),
);
$params['birth_date_low'] = array('name' => 'birth_date_low', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or greater than'));
$params['birth_date_high'] = array('name' => 'birth_date_high', 'type' => CRM_Utils_Type::T_DATE, 'title' => ts('Birth Date is equal to or less than'));
* @return bool|string
* fieldName or FALSE if the field does not exist
*/
-function _civicrm_api3_api_resolve_alias($entity, $fieldName) {
+function _civicrm_api3_api_resolve_alias($entity, $fieldName, $action = 'create') {
if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
return $fieldName;
}
}
$result = civicrm_api($entity, 'getfields', array(
'version' => 3,
- 'action' => 'create',
+ 'action' => $action,
));
$meta = $result['values'];
if (!isset($meta[$fieldName]['name']) && isset($meta[$fieldName . '_id'])) {
return $info['name'];
}
}
+ // Create didn't work, try with get
+ if ($action == 'create') {
+ return _civicrm_api3_api_resolve_alias($entity, $fieldName, 'get');
+ }
return FALSE;
}