Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
More accurately guess whether a custom field has an option list
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jul 25, 2018
1 parent f35ed9c commit be51a9d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Civi/Api4/Service/Spec/SpecFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function arrayToField(array $data, $entity) {
$field->setCustomGroupId($data['custom_group_id']);
$field->setRequired((bool) ArrayHelper::value('is_required', $data, FALSE));
$field->setTitle(ArrayHelper::value('label', $data));
$field->setOptions(!empty($data['option_group_id']));
$field->setOptions(self::customFieldHasOptions($data));
if (\CRM_Core_BAO_CustomField::isSerialized($data)) {
$field->setSerialize(\CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND);
}
Expand All @@ -68,6 +68,28 @@ public static function arrayToField(array $data, $entity) {
return $field;
}

/**
* Does this custom field have options
*
* @param array $field
* @return bool
*/
private static function customFieldHasOptions($field) {
// This will include boolean fields with Yes/No options.
if (in_array($field['html_type'], ['Radio', 'CheckBox'])) {
return TRUE;
}
// Do this before the "Select" string search because date fields have a "Select Date" html_type
// and contactRef fields have an "Autocomplete-Select" html_type - contacts are an FK not an option list.
if (in_array($field['data_type'], ['ContactReference', 'Date'])) {
return FALSE;
}
if (strpos($field['html_type'], 'Select')) {
return TRUE;
}
return !empty($field['option_group_id']);
}

/**
* Get the data type from an array. Defaults to 'data_type' with fallback to
* mapping for the integer value 'type'
Expand Down

0 comments on commit be51a9d

Please sign in to comment.