*
* Generated from xml/schema/CRM/Core/CustomField.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:200b28277fc9e025b42d3f3e45fde020)
+ * (GenCodeChecksum:1acb9b3538bd3005b99e6af6d9ec062f)
*/
/**
public $option_group_id;
/**
- * Serialization method - a non-null value indicates a multi-valued field.
+ * Serialization method - a non-zero value indicates a multi-valued field.
*
* @var int
*/
'name' => 'serialize',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Serialize'),
- 'description' => ts('Serialization method - a non-null value indicates a multi-valued field.'),
+ 'description' => ts('Serialization method - a non-zero value indicates a multi-valued field.'),
+ 'required' => TRUE,
'where' => 'civicrm_custom_field.serialize',
+ 'default' => '0',
'table_name' => 'civicrm_custom_field',
'entity' => 'CustomField',
'bao' => 'CRM_Core_BAO_CustomField',
--- /dev/null
+{* file to handle db changes in 5.29.1 during upgrade *}
+
+UPDATE `civicrm_custom_field` SET `serialize` = 0 WHERE `serialize` IS NULL;
+
+ALTER TABLE `civicrm_custom_field`
+CHANGE COLUMN `serialize`
+`serialize` int unsigned NOT NULL DEFAULT 0 COMMENT 'Serialization method - a non-zero value indicates a multi-valued field.';
* @return array
*/
function civicrm_api3_custom_field_get($params) {
- if (CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1') && ($params['legacy_html_type'] ?? TRUE) && !empty($params['return'])) {
- if (is_array($params['return'])) {
+ // Legacy handling for serialize property
+ $handleLegacy = (($params['legacy_html_type'] ?? !isset($params['serialize'])) && CRM_Core_BAO_Domain::isDBVersionAtLeast('5.27.alpha1'));
+ if ($handleLegacy && !empty($params['return'])) {
+ if (!is_array($params['return'])) {
+ $params['return'] = explode(',', str_replace(' ', '', $params['return']));
+ }
+ if (!in_array('serialize', $params['return'])) {
$params['return'][] = 'serialize';
}
- elseif (is_string($params['return'])) {
- $params['return'] .= ',serialize';
+ }
+ if ($handleLegacy && !empty($params['html_type'])) {
+ $serializedTypes = ['CheckBox', 'Multi-Select', 'Multi-Select Country', 'Multi-Select State/Province'];
+ if (is_string($params['html_type'])) {
+ if (strpos($params['html_type'], 'Multi-Select') === 0) {
+ $params['html_type'] = str_replace('Multi-Select', 'Select', $params['html_type']);
+ $params['serialize'] = 1;
+ }
+ elseif (!in_array($params['html_type'], $serializedTypes)) {
+ $params['serialize'] = 0;
+ }
+ }
+ 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);
+ }, $params['html_type']['IN']);
+ if ($excludeNonSerialized) {
+ $params['serialize'] = 1;
+ }
+ if ($onlyNonSerialized) {
+ $params['serialize'] = 0;
+ }
}
}
$results = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
- if (($params['legacy_html_type'] ?? TRUE) && !empty($results['values']) && is_array($results['values'])) {
+ 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']);
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('country'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
'pseudoconstant' => [
'table' => 'civicrm_country',
'keyColumn' => 'id',
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.my_file_' . $this->getCustomFieldID('file'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('text') => [
'name' => $this->getCustomFieldName('text'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
'maxlength' => 300,
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('select_string') => [
'name' => $this->getCustomFieldName('select_string'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.pick_color_' . $this->getCustomFieldID('select_string'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
'pseudoconstant' => [
'optionGroupName' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
'optionEditPath' => 'civicrm/admin/options/' . $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_date_' . $this->getCustomFieldID('select_date'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('link') => [
'name' => $this->getCustomFieldName('link'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_link_' . $this->getCustomFieldID('link'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('int') => [
'name' => $this->getCustomFieldName('int'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('int'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('contact_reference') => [
'name' => $this->getCustomFieldName('contact_reference'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('contact_reference'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
],
$this->getCustomFieldName('state') => [
'name' => $this->getCustomFieldName('state'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('state'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
- 'serialize' => NULL,
+ 'serialize' => 0,
'pseudoconstant' => [
'table' => 'civicrm_state_province',
'keyColumn' => 'id',
'text_length' => NULL,
'options_per_line' => NULL,
'is_search_range' => '0',
- 'serialize' => NULL,
+ 'serialize' => 0,
'pseudoconstant' => [
'callback' => 'CRM_Core_SelectValues::boolean',
],
'type' => 4,
'where' => 'civicrm_value_testsearchcus_' . $ids['custom_group_id'] . '.date_field_' . $dateCustomField['id'],
'import' => 1,
- 'serialize' => NULL,
+ 'serialize' => 0,
], $queryObj->getFieldSpec('custom_' . $dateCustomField['id']));
}
<is_active>1</is_active>
<is_view>0</is_view>
<column_name>name1_1</column_name>
+ <serialize>0</serialize>
<in_selector>0</in_selector>
<custom_group_name>example</custom_group_name>
</CustomField>
<is_active>1</is_active>
<is_view>0</is_view>
<column_name>name1_1</column_name>
+ <serialize>0</serialize>
<in_selector>0</in_selector>
<custom_group_name>example</custom_group_name>
</CustomField>
<is_active>1</is_active>
<is_view>0</is_view>
<column_name>name1_1</column_name>
+ <serialize>0</serialize>
<in_selector>0</in_selector>
<custom_group_name>example</custom_group_name>
</CustomField>
<is_active>1</is_active>
<is_view>0</is_view>
<column_name>name1_1</column_name>
+ <serialize>0</serialize>
<in_selector>0</in_selector>
<custom_group_name>example</custom_group_name>
</CustomField>
<is_active>1</is_active>
<is_view>0</is_view>
<column_name>name1_1</column_name>
+ <serialize>0</serialize>
<in_selector>0</in_selector>
<custom_group_name>example</custom_group_name>
</CustomField>
$this->callAPISuccess('CustomField', 'create', $params);
}
+ public function testLegacyHtmlType() {
+ $customGroup = $this->customGroupCreate([
+ 'name' => 'testCustomGroup',
+ 'title' => 'testCustomGroup',
+ 'extends' => 'Individual',
+ ]);
+ $f1 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'SingleSelect',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'String',
+ 'html_type' => 'Select',
+ 'option_values' => [1 => 'One', 2 => 'Two'],
+ ]);
+ $f2 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'CheckBoxes',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'String',
+ 'html_type' => 'CheckBox',
+ 'option_values' => [1 => 'One', 2 => 'Two'],
+ ]);
+ $f3 = $this->callAPISuccess('CustomField', 'create', [
+ 'label' => 'MultiSelect',
+ 'custom_group_id' => 'testCustomGroup',
+ 'data_type' => 'String',
+ 'html_type' => 'Multi-Select',
+ 'option_values' => [1 => 'One', 2 => 'Two'],
+ ]);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Multi-Select',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('MultiSelect', $result['values'][0]['label']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => ['IN' => ['Multi-Select', 'CheckBox']],
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(2, $result['values']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => 'Select',
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('SingleSelect', $result['values'][0]['label']);
+
+ $result = $this->callAPISuccess('CustomField', 'get', [
+ 'custom_group_id' => 'testCustomGroup',
+ 'html_type' => ['IN' => ['Select']],
+ 'sequential' => 1,
+ ]);
+ $this->assertCount(1, $result['values']);
+ $this->assertEquals('SingleSelect', $result['values'][0]['label']);
+ }
+
}
'entity' => "Custom_$group",
'data_type' => 'String',
'fk_entity' => NULL,
- 'serialize' => NULL,
+ 'serialize' => 0,
'options' => $optionValues,
],
[
'entity' => "Custom_$group",
'data_type' => 'String',
'fk_entity' => NULL,
- 'serialize' => NULL,
+ 'serialize' => 0,
],
[
'name' => 'id',
<type>int unsigned</type>
<title>Serialize</title>
<length>255</length>
- <comment>Serialization method - a non-null value indicates a multi-valued field.</comment>
+ <comment>Serialization method - a non-zero value indicates a multi-valued field.</comment>
<pseudoconstant>
<callback>CRM_Core_SelectValues::fieldSerialization</callback>
</pseudoconstant>
<add>5.27</add>
+ <required>true</required>
+ <default>0</default>
</field>
<field>
<name>filter</name>