'option_group_id' => NULL,
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '0',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
'column_name' => 'country_' . $this->getCustomFieldID('country'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.country_' . $this->getCustomFieldID('country'),
$this->getCustomFieldName('file') => [
'name' => $this->getCustomFieldName('file'),
'type' => 2,
- 'title' => 'Custom Field',
+ 'title' => 'My file',
'headerPattern' => '//',
'import' => 1,
'custom_field_id' => $this->getCustomFieldID('file'),
'html_type' => 'File',
'is_search_range' => '0',
'id' => $this->getCustomFieldID('file'),
- 'label' => 'Custom Field',
+ 'label' => 'My file',
'groupTitle' => 'Custom Group',
'default_value' => NULL,
'custom_group_id' => $customGroupID,
'option_group_id' => NULL,
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '0',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
- 'column_name' => 'custom_field_' . $this->getCustomFieldID('file'),
- 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.custom_field_' . $this->getCustomFieldID('file'),
+ 'column_name' => 'my_file_' . $this->getCustomFieldID('file'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.my_file_' . $this->getCustomFieldID('file'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
],
'option_group_id' => NULL,
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '1',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
'column_name' => 'enter_text_here_' . $this->getCustomFieldID('text'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.enter_text_here_' . $this->getCustomFieldID('text'),
'option_group_id' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id']),
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '1',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
'column_name' => 'pick_color_' . $this->getCustomFieldID('select_string'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.pick_color_' . $this->getCustomFieldID('select_string'),
'option_group_id' => NULL,
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '1',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
'column_name' => 'test_link_' . $this->getCustomFieldID('link'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_link_' . $this->getCustomFieldID('link'),
'option_group_id' => NULL,
'date_format' => NULL,
'time_format' => NULL,
- 'is_required' => '1',
+ 'is_required' => 0,
'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
'column_name' => $this->getCustomFieldColumnName('int'),
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('int'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
],
+ $this->getCustomFieldName('contact_reference') => [
+ 'name' => $this->getCustomFieldName('contact_reference'),
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => 'Contact reference field',
+ 'headerPattern' => '//',
+ 'import' => 1,
+ 'custom_field_id' => $this->getCustomFieldID('contact_reference'),
+ 'options_per_line' => NULL,
+ 'text_length' => NULL,
+ 'data_type' => 'ContactReference',
+ 'html_type' => 'Autocomplete-Select',
+ 'is_search_range' => '0',
+ 'id' => $this->getCustomFieldID('contact_reference'),
+ 'label' => 'Contact reference field',
+ 'groupTitle' => 'Custom Group',
+ 'default_value' => NULL,
+ 'custom_group_id' => $customGroupID,
+ 'extends' => 'Contact',
+ 'extends_entity_column_value' => NULL,
+ 'extends_entity_column_id' => NULL,
+ 'is_view' => '0',
+ 'is_multiple' => '0',
+ 'option_group_id' => NULL,
+ 'date_format' => NULL,
+ 'time_format' => NULL,
+ 'is_required' => 0,
+ 'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+ 'column_name' => $this->getCustomFieldColumnName('contact_reference'),
+ 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('contact_reference'),
+ 'extends_table' => 'civicrm_contact',
+ 'search_table' => 'contact_a',
+ ],
];
$this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport());
}
$this->assertEquals($expectedDisplayValue, CRM_Core_BAO_CustomField::displayValue($file['id'], $fileField['id']));
}
+ /**
+ * Test for hook_civicrm_alterCustomFieldDisplayValue().
+ */
+ public function testAlterCustomFieldDisplayValueHook() {
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_alterCustomFieldDisplayValue', [$this, 'alterCustomFieldDisplayValue']);
+ $customGroupId = $this->customGroupCreate([
+ 'extends' => 'Individual',
+ 'title' => 'Test Contactcustom Group',
+ ])['id'];
+ $fieldId = $this->customFieldCreate([
+ 'custom_group_id' => $customGroupId,
+ 'name' => 'alter_cf_field',
+ 'label' => 'Alter CF Field',
+ ])['id'];
+ $contactId = $this->individualCreate(['custom_' . $fieldId => 'Test']);
+
+ $this->assertEquals('Test', $this->callAPISuccessGetValue('Contact',
+ ['id' => $contactId, 'return' => "custom_{$fieldId}"]
+ ));
+
+ $values = [];
+ $fields = [
+ 'custom_' . $fieldId => $this->callAPISuccess('Contact', 'getfield', [
+ 'name' => 'custom_' . $fieldId,
+ 'action' => 'get',
+ ])['values'],
+ ];
+
+ // CRM_Core_BAO_UFGroup::getValues() invokes CRM_Core_BAO_CustomField::displayValue() function.
+ CRM_Core_BAO_UFGroup::getValues($contactId, $fields, $values);
+ $this->assertEquals('New value', $values['Alter CF Field']);
+ }
+
+ /**
+ * @param string $displayValue
+ * @param mixed $value
+ * @param int $entityId
+ * @param array $fieldInfo
+ *
+ */
+ public function alterCustomFieldDisplayValue(&$displayValue, $value, $entityId, $fieldInfo) {
+ if ($fieldInfo['name'] == 'alter_cf_field') {
+ $displayValue = 'New value';
+ }
+ }
+
}