Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#2459 Fix custom fields changed from multiple-choice data type to Text #19794

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,11 @@ protected static function prepareCreate($params) {
}
}

// Remove option group IDs from fields changed to Text html_type.
if ($htmlType == 'Text') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change. Are there other html types this should also apply to?

$params['option_group_id'] = '';
}

// check for orphan option groups
if (!empty($params['option_group_id'])) {
if (!empty($params['id'])) {
Expand Down
28 changes: 28 additions & 0 deletions tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ public function testCreateCustomField() {
$this->customGroupDelete($customGroup['id']);
}

/**
* Test changing a data type from multiple-choice to Text.
*/
public function testChangeDataType() {
$customGroup = $this->createCustomField();
$fields = [
'label' => 'Radio to Text',
'is_active' => 1,
'data_type' => 'String',
'html_type' => 'Radio',
'custom_group_id' => $customGroup['id'],
'option_type' => 1,
'option_label' => ["One", "Two"],
'option_value' => [1, 2],
'option_weight' => [1, 2],
'option_status' => [1, 1],
];
$customField = CRM_Core_BAO_CustomField::create($fields);
$this->assertNotNull($customField->option_group_id);
$fieldsNew = [
'id' => $customField->id,
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
];
$customFieldModified = CRM_Core_BAO_CustomField::create($fieldsNew);
$this->assertFalse($customFieldModified->option_group_id ?? FALSE);
}

/**
* Test custom field create accepts passed column name.
*/
Expand Down