$fields = $d->fields();
// replace uniqueNames by the normal names as the key
if (empty($unique)) {
- foreach ($fields as $name => & $field) {
+ foreach ($fields as $name => &$field) {
//getting rid of unused attributes
foreach ($unsetIfEmpty as $attr) {
if (empty($field[$attr])) {
unset($fields[$name]);
}
}
+ // Translate FKClassName to the corresponding api
+ foreach ($fields as $name => &$field) {
+ if (!empty($field['FKClassName'])) {
+ $FKApi = CRM_Core_DAO_AllCoreTables::getBriefName($field['FKClassName']);
+ if ($FKApi) {
+ $field['FKApiName'] = $FKApi;
+ }
+ }
+ }
$fields += _civicrm_api_get_custom_fields($entity, $params);
return $fields;
}
action,
actions = ['get'],
fields = [],
+ getFieldData = {},
options = {},
params = {},
smartyStub,
function getFields() {
var required = [];
fields = [];
- options = {};
+ options = getFieldData = {};
// Special case for getfields
if (action === 'getfields') {
fields.push({
showFields(['api_action']);
return;
}
- CRM.api3(entity, 'getFields', {'api_action': action, sequential: 1, options: {get_options: 'all'}}).done(function(data) {
+ CRM.api3(entity, 'getFields', {'api_action': action, options: {get_options: 'all'}}).done(function(data) {
+ getFieldData = data.values;
_.each(data.values, function(field) {
if (field.name) {
fields.push({
}
/**
- * Render value input as a textfield, option list, or hidden,
+ * Render value input as a textfield, option list, entityRef, or hidden,
* Depending on selected param name and operator
*/
function renderValueField() {
return;
}
$valField.css('visibility', '');
- // Option list input
- if (options[name] && $.inArray(operator, TEXT) < 0) {
+ // Option list or entityRef input
+ if ((options[name] || (getFieldData[name] && getFieldData[name].FKApiName)) && $.inArray(operator, TEXT) < 0) {
// Reset value before switching to a select from something else
if ($(this).is('.api-param-name') || !$valField.data('select2')) {
$valField.val('');
else if (operatorType == 'single' && currentVal.indexOf(',') > -1) {
$valField.val(currentVal.split(',')[0]);
}
- $valField.select2({
- multiple: (operatorType === 'multi'),
- data: _.transform(options[name], function(result, option) {
- result.push({id: option.key, text: option.value});
- })
- });
+ // Select options
+ if (options[name]) {
+
+ $valField.select2({
+ multiple: (operatorType === 'multi'),
+ data: _.map(options[name], function (value, key) {
+ return {id: key, text: value};
+ })
+ });
+ }
+ // EntityRef
+ else {
+ $valField.crmEntityRef({
+ entity: getFieldData[name].FKApiName,
+ select: {multiple: (operatorType === 'multi')}
+ });
+ }
return;
}
// Plain text input