The html_type 'Select Country' and 'Select State/Province' serve no purpose. They are the same as Select, just with a different data_type.
This adds an APIv3 shim to display the old types.
// This provides legacy support for APIv3, allowing no-longer-existent html types
if ($fieldName == 'html_type' && isset($props['version']) && $props['version'] == 3) {
$options['Multi-Select'] = 'Multi-Select';
+ $options['Select Country'] = 'Select Country';
$options['Multi-Select Country'] = 'Multi-Select Country';
+ $options['Select State/Province'] = 'Select State/Province';
$options['Multi-Select State/Province'] = 'Multi-Select State/Province';
}
return $options;
$placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
- // FIXME: Why are select state/country separate widget types?
$isSelect = (in_array($widget, [
'Select',
- 'Select State/Province',
- 'Select Country',
'CheckBox',
'Radio',
]));
case 'Select':
case 'Autocomplete-Select':
case 'Radio':
- case 'Select Country':
- case 'Select State/Province':
case 'CheckBox':
if ($field['data_type'] == 'ContactReference' && $value) {
if (is_numeric($value)) {
'CheckBox' => ts('Checkbox(es)'),
'Select Date' => ts('Select Date'),
'File' => ts('File'),
- 'Select State/Province' => ts('Select State/Province'),
- 'Select Country' => ts('Select Country'),
'RichTextEditor' => ts('Rich Text Editor'),
'Autocomplete-Select' => ts('Autocomplete-Select'),
'Link' => ts('Link'),
['TextArea' => 'TextArea', 'RichTextEditor' => 'RichTextEditor'],
['Date' => 'Select Date'],
['Radio' => 'Radio'],
- ['StateProvince' => 'Select State/Province'],
- ['Country' => 'Select Country'],
+ ['StateProvince' => 'Select'],
+ ['Country' => 'Select'],
['File' => 'File'],
['Link' => 'Link'],
['ContactReference' => 'Autocomplete-Select'],
['TextArea' => ts('TextArea'), 'RichTextEditor' => ts('Rich Text Editor')],
['Date' => ts('Select Date')],
['Radio' => ts('Radio')],
- ['StateProvince' => ts('Select State/Province')],
- ['Country' => ts('Select Country')],
+ ['StateProvince' => ts('Select')],
+ ['Country' => ts('Select')],
['File' => ts('Select File')],
['Link' => ts('Link')],
['ContactReference' => ts('Autocomplete-Select')],
case 'Radio':
case 'Select':
- case 'Select Country':
- case 'Select State/Province':
$editable = TRUE;
$fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
if (!$spec['is_required']) {
$headers = [];
if (!empty($fieldIDs)) {
- $fields = ['Radio', 'Select', 'Select Country', 'Select State/Province'];
+ $fields = ['Radio', 'Select'];
foreach ($fieldIDs as $fieldID) {
if ($this->_pageViewType == 'profileDataView') {
$headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
{* file to handle db changes in 5.31.alpha1 during upgrade *}
+
+{* Remove Country & State special select fields *}
+UPDATE civicrm_custom_field SET html_type = 'Select'
+WHERE html_type IN ('Select Country', 'Select State/Province');
unset($inputAttrs['type']);
$map = [
- 'Select State/Province' => 'Select',
- 'Select Country' => 'Select',
'Select Date' => 'Date',
'Link' => 'Url',
];
function civicrm_api3_custom_field_create($params) {
// Legacy handling for old way of naming serialized fields
- if (!empty($params['html_type']) && ($params['html_type'] == 'CheckBox' || strpos($params['html_type'], 'Multi-') === 0)) {
- $params['serialize'] = 1;
- $params['html_type'] = str_replace('Multi-', '', $params['html_type']);
+ if (!empty($params['html_type'])) {
+ if ($params['html_type'] == 'CheckBox' || strpos($params['html_type'], 'Multi-') === 0) {
+ $params['serialize'] = 1;
+ }
+ $params['html_type'] = str_replace(['Multi-Select', 'Select Country', 'Select State/Province'], 'Select', $params['html_type']);
}
// Array created for passing options in params.
if (!in_array('serialize', $params['return'])) {
$params['return'][] = 'serialize';
}
+ if (!in_array('data_type', $params['return'])) {
+ $params['return'][] = 'data_type';
+ }
}
+ $legacyDataTypes = [
+ 'Select State/Province' => 'StateProvince',
+ 'Select Country' => 'Country',
+ ];
if ($handleLegacy && !empty($params['html_type'])) {
$serializedTypes = ['CheckBox', 'Multi-Select', 'Multi-Select Country', 'Multi-Select State/Province'];
if (is_string($params['html_type'])) {
elseif (!in_array($params['html_type'], $serializedTypes)) {
$params['serialize'] = 0;
}
+ if (isset($legacyDataTypes[$params['html_type']])) {
+ $params['data_type'] = $legacyDataTypes[$params['html_type']];
+ unset($params['html_type']);
+ }
}
elseif (is_array($params['html_type']) && !empty($params['html_type']['IN'])) {
$excludeNonSerialized = !array_diff($params['html_type']['IN'], $serializedTypes);
$onlyNonSerialized = !array_intersect($params['html_type']['IN'], $serializedTypes);
$params['html_type']['IN'] = array_map(function($val) {
- return str_replace('Multi-Select', 'Select', $val);
+ return str_replace(['Multi-Select', 'Select Country', 'Select State/Province'], 'Select', $val);
}, $params['html_type']['IN']);
if ($excludeNonSerialized) {
$params['serialize'] = 1;
$results = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
- if ($handleLegacy && !empty($results['values']) && is_array($results['values']) && !isset($params['serialize'])) {
- foreach ($results['values'] as $id => $result) {
- if (!empty($result['serialize']) && !empty($result['html_type'])) {
- $results['values'][$id]['html_type'] = str_replace('Select', 'Multi-Select', $result['html_type']);
+ if ($handleLegacy && !empty($results['values']) && is_array($results['values'])) {
+ foreach ($results['values'] as $id => &$result) {
+ if (!empty($result['html_type'])) {
+ if (in_array($result['data_type'], $legacyDataTypes)) {
+ $result['html_type'] = array_search($result['data_type'], $legacyDataTypes);
+ }
+ if (!empty($result['serialize'])) {
+ $result['html_type'] = str_replace('Select', 'Multi-Select', $result['html_type']);
+ }
}
}
}
$fieldsToCreate = [
[
'data_type' => 'Country',
- 'html_type' => 'Select Country',
+ 'html_type' => 'Select',
'tests' => [
'United States' => 1228,
'' => NULL,
],
[
'data_type' => 'StateProvince',
- 'html_type' => 'Multi-Select State/Province',
+ 'html_type' => 'Select',
+ 'serialize' => 1,
'tests' => [
'' => 0,
'Alabama' => 1000,
'custom_group_id' => $groups['A']['id'],
'label' => 'Country A',
'dataType' => 'Country',
- 'htmlType' => 'Select Country',
+ 'htmlType' => 'Select',
'default_value' => NULL,
]);
$countryB = $this->customFieldCreate([
'custom_group_id' => $groups['A']['id'],
'label' => 'Country B',
'dataType' => 'Country',
- 'htmlType' => 'Select Country',
+ 'htmlType' => 'Select',
'default_value' => NULL,
]);
$countryC = $this->customFieldCreate([
'custom_group_id' => $groups['B']['id'],
'label' => 'Country C',
'dataType' => 'Country',
- 'htmlType' => 'Select Country',
+ 'htmlType' => 'Select',
'default_value' => NULL,
]);
'options_per_line' => NULL,
'text_length' => NULL,
'data_type' => 'Country',
- 'html_type' => 'Select Country',
+ 'html_type' => 'Select',
'is_search_range' => '0',
'id' => $this->getCustomFieldID('country'),
'label' => 'Country',
'options_per_line' => NULL,
'text_length' => NULL,
'data_type' => 'Country',
- 'html_type' => 'Select Country',
+ 'html_type' => 'Select',
'is_search_range' => '0',
'id' => $this->getCustomFieldID('multi_country'),
'label' => 'Country-multi',
'import' => 1,
'data_type' => 'StateProvince',
'type' => 1,
- 'html_type' => 'Select State/Province',
+ 'html_type' => 'Select',
'text_length' => NULL,
'options_per_line' => NULL,
'is_search_range' => '0',
'data_type' => 'StateProvince',
'name' => $this->getCustomFieldName('multi_state'),
'type' => 1,
- 'html_type' => 'Select State/Province',
+ 'html_type' => 'Select',
'text_length' => NULL,
'options_per_line' => NULL,
'is_search_range' => '0',
$fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'StateProvince',
- 'html_type' => 'Select State/Province',
+ 'html_type' => 'Select',
'default_value' => '',
];
$dtype = CRM_Core_BAO_CustomField::dataType();
$htype = CRM_Custom_Form_Field::$_dataToHTML;
+ // Legacy html types returned by v3
+ foreach ($htype as &$item) {
+ if (isset($item['StateProvince'])) {
+ $item['StateProvince'] = 'Select State/Province';
+ }
+ if (isset($item['Country'])) {
+ $item['Country'] = 'Select Country';
+ }
+ }
+
$n = 0;
foreach ($dtype as $dkey => $dvalue) {
foreach ($htype[$n] as $hkey => $hvalue) {
$this->assertEquals('SingleSelect', $result['values'][0]['label']);
}
+ public function testLegacyStateCountryTypes() {
+ $customGroup = $this->customGroupCreate([
+ 'name' => 'testCustomGroup',
+ 'title' => 'testCustomGroup',
+ 'extends' => 'Individual',
+ ]);
+ $f1 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'CountrySelect',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'Country',
+ 'html_type' => 'Select Country',
+ ]);
+ $f2 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'StateSelect',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'StateProvince',
+ 'html_type' => 'Select State/Province',
+ ]);
+ $f3 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'MultiSelectSP',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'StateProvince',
+ 'html_type' => 'Multi-Select State/Province',
+ ]);
+ $f4 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'MultiSelectCountry',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'Country',
+ 'html_type' => 'Select Country',
+ 'serialize' => 1,
+ ]);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Multi-Select State/Province',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('MultiSelectSP', $result['values'][0]['label']);
+ $this->assertEquals('Multi-Select State/Province', $result['values'][0]['html_type']);
+ $this->assertEquals('1', $result['values'][0]['serialize']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Multi-Select Country',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('MultiSelectCountry', $result['values'][0]['label']);
+ $this->assertEquals('Multi-Select Country', $result['values'][0]['html_type']);
+ $this->assertEquals('1', $result['values'][0]['serialize']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Select Country',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('CountrySelect', $result['values'][0]['label']);
+ $this->assertEquals('Select Country', $result['values'][0]['html_type']);
+ $this->assertEquals('0', $result['values'][0]['serialize']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Select State/Province',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('StateSelect', $result['values'][0]['label']);
+ $this->assertEquals('Select State/Province', $result['values'][0]['html_type']);
+ $this->assertEquals('0', $result['values'][0]['serialize']);
+ }
+
}