public static $_importFields = NULL;
/**
- * Build and retrieve the list of data types and descriptions
+ * Build and retrieve the list of data types and descriptions.
*
* @return array
* Data type => Description
}
/**
- * Takes an associative array and creates a custom field object
+ * Takes an associative array and creates a custom field object.
*
* This function is invoked from within the web form layer and also from the api layer
*
$customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE);
$customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE);
$customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE);
- $customField->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
+ //CRM-15792 - Custom field gets disabled if is_active not set
+ $customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE);
$customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE);
$customField->save();
}
/**
- * Fetch object based on array of properties
+ * Fetch object based on array of properties.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
}
/**
- * Update the is_active flag in the db
+ * Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
$cfTable.option_group_id,
$cfTable.date_format,
$cfTable.time_format,
- $cgTable.is_multiple
+ $cgTable.is_multiple,
+ og.name as option_group_name
FROM $cfTable
INNER JOIN $cgTable
- ON $cfTable.custom_group_id = $cgTable.id
+ ON $cfTable.custom_group_id = $cgTable.id
+ LEFT JOIN civicrm_option_group og
+ ON $cfTable.option_group_id = og.id
WHERE ( 1 ) ";
if (!$showAll) {
$fields[$dao->id]['date_format'] = $dao->date_format;
$fields[$dao->id]['time_format'] = $dao->time_format;
$fields[$dao->id]['is_required'] = $dao->is_required;
+ self::getOptionsForField($fields[$dao->id], $dao->option_group_name);
}
CRM_Core_BAO_Cache::setItem($fields,
}
/**
- * Get the field id from an import key
+ * Get the field id from an import key.
*
* @param string $key
* The key to parse.
}
/**
- * Use the cache to get all values of a specific custom field
+ * Use the cache to get all values of a specific custom field.
*
* @param int $fieldID
* The custom field ID.
}
/**
- * This function for building custom fields
+ * This function for building custom fields.
*
* @param CRM_Core_Form $qf
* Form object (reference).
break;
case 'File':
- if ($contactID) {
+ // In the context of displaying a profile, show file/image
+ if ($contactID && $value) {
$url = self::getFileURL($contactID, $fieldID, $value);
if ($url) {
$display = $url['file_url'];
}
}
+ // In other contexts show a paperclip icon
+ elseif ($value) {
+ $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
+ $display = $icons[$value];
+ }
break;
case 'TextArea':
}
/**
- * Set default values for custom data used in profile
+ * Set default values for custom data used in profile.
*
* @param int $customFieldId
* Custom field id.
}
/**
- * Format custom fields before inserting
+ * Format custom fields before inserting.
*
* @param int $customFieldId
* Custom field id.
//subtype and basic type
$customDataSubType = NULL;
if (is_array($customFieldExtend)) {
- $customFieldExtend = $customFieldExtend[0];
- }
-
- if (in_array($customFieldExtend,
- CRM_Contact_BAO_ContactType::subTypes()
- )) {
// This is the case when getFieldsForImport() requires fields
// of subtype and its parent.CRM-5143
- $customDataSubType = $customFieldExtend;
- $customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType);
+ // CRM-16065 - Custom field set data not being saved if contact has more than one contact sub type
+ $customDataSubType = array_intersect(CRM_Contact_BAO_ContactType::subTypes(), (array) $customFieldExtend);
+ if (!empty($customDataSubType) && is_array($customDataSubType)) {
+ $customFieldExtend = array_unique(array_values(CRM_Contact_BAO_ContactType::getBasicType($customDataSubType)));
+ }
}
$customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend,
}
/**
- * Determine whether it would be safe to move a field
+ * Determine whether it would be safe to move a field.
*
* @param int $fieldID
* FK to civicrm_custom_field.
}
/**
- * Get the database table name and column name for a custom field
+ * Get the database table name and column name for a custom field.
*
* @param int $fieldID
* The fieldID of the custom field.
}
/**
- * Get custom option groups
+ * Get custom option groups.
*
* @param array $includeFieldIds
* Ids of custom fields for which.
}
/**
- * Fix orphan groups
+ * Fix orphan groups.
*
* @param int $customFieldId
* Custom field id.
/**
* Given ID of a custom field, return its name as well as the name of the custom group it belongs to.
+ *
+ * @param array $ids
+ *
+ * @return array
*/
public static function getNameFromID($ids) {
if (is_array($ids)) {
return ($field['html_type'] == 'CheckBox' || strpos($field['html_type'], 'Multi') !== FALSE);
}
+ /**
+ * @param array $field
+ * @param string|null $optionGroupName
+ */
+ private static function getOptionsForField(&$field, $optionGroupName) {
+ if ($optionGroupName) {
+ $field['pseudoconstant'] = array(
+ 'optionGroupName' => $optionGroupName,
+ 'optionEditPath' => 'civicrm/admin/options/' . $optionGroupName,
+ );
+ }
+ elseif ($field['data_type'] == 'Boolean') {
+ $field['pseudoconstant'] = array(
+ 'callback' => 'CRM_Core_SelectValues::boolean',
+ );
+ }
+ elseif ($field['data_type'] == 'Country') {
+ $field['pseudoconstant'] = array(
+ 'table' => 'civicrm_country',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'name',
+ 'nameColumn' => 'iso_code',
+ );
+ }
+ elseif ($field['data_type'] == 'StateProvince') {
+ $field['pseudoconstant'] = array(
+ 'table' => 'civicrm_state_province',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'name',
+ );
+ }
+ }
+
}