Skip to content

Commit

Permalink
Merge pull request #17569 from JMAConsulting/core-1805
Browse files Browse the repository at this point in the history
core#1805: Autocomplete-select custom field is not searchable
  • Loading branch information
eileenmcnaughton authored Jul 14, 2020
2 parents 868c96c + 2fd2f7b commit caec1f1
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 32 deletions.
2 changes: 0 additions & 2 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ public function postProcess() {
$this->_formValues["activity_test"] = 0;
}

CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);

$this->set('queryParams', $this->_queryParams);
Expand Down
2 changes: 0 additions & 2 deletions CRM/Case/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ public function postProcess() {
if (empty($this->_formValues['case_deleted'])) {
$this->_formValues['case_deleted'] = 0;
}
// @todo - stop changing formValues - respect submitted form values, change a working array.
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

// @todo - stop changing formValues - respect submitted form values, change a working array.
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
Expand Down
1 change: 1 addition & 0 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
}

self::filterCountryFromValuesIfStateExists($formValues);
CRM_Core_BAO_CustomValue::fixCustomFieldValue($formValues);

foreach ($formValues as $id => $values) {
if (self::isAlreadyProcessedForQueryFormat($values)) {
Expand Down
2 changes: 0 additions & 2 deletions CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ public function postProcess() {
$this->_sortByCharacter = NULL;
}

CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

$this->_params = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);
$this->_returnProperties = &$this->returnProperties();
parent::postProcess();
Expand Down
3 changes: 0 additions & 3 deletions CRM/Contribute/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ public function postProcess() {
}
}

// @todo - stop changing formValues - respect submitted form values, change a working array.
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

// @todo - stop changing formValues - respect submitted form values, change a working array.
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);

Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/BAO/CustomValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public static function fixCustomFieldValue(&$formValues) {
) {
$formValues[$key] = ['LIKE' => $formValues[$key]];
}
elseif ($htmlType == 'Autocomplete-Select' && !empty($formValues[$key]) && is_string($formValues[$key]) && (strpos($formValues[$key], ',') != FALSE)) {
$formValues[$key] = ['IN' => explode(',', $formValues[$key])];
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ private function submit($formValues) {
$this->_formValues["participant_test"] = 0;
}

CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']);

$this->set('queryParams', $this->_queryParams);
Expand Down
2 changes: 0 additions & 2 deletions CRM/Grant/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ public function postProcess() {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}

CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);

$this->set('queryParams', $this->_queryParams);
Expand Down
2 changes: 0 additions & 2 deletions CRM/Member/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ public function postProcess() {
$this->_formValues["member_test"] = 0;
}

CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, $this->entityReferenceFields);

$this->set('queryParams', $this->_queryParams);
Expand Down
66 changes: 49 additions & 17 deletions tests/phpunit/CRM/Core/BAO/CustomValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,60 @@ public function testTypeToFieldWithWrongInput() {
}
}

public function fixCustomFieldValue() {
public function testFixCustomFieldValue() {
$customGroup = $this->customGroupCreate(['extends' => 'Individual']);

$fields = [
'custom_group_id' => $customGroup['id'],
'data_type' => 'Memo',
'html_type' => 'TextArea',
'default_value' => '',
];

$customField = $this->customFieldCreate($fields);

$custom = 'custom_' . $customField['id'];
$params = [
'email' => 'abc@webaccess.co.in',
$custom => 'note',
'email' => 'abc@example.com',
];

CRM_Core_BAO_CustomValue::fixCustomFieldValue($params);
$this->assertEquals($params[$custom], '%note%', 'Checking the returned value of type Memo.');
foreach ([
[
'custom_group_id' => $customGroup['id'],
'data_type' => 'Memo',
'html_type' => 'TextArea',
'default_value' => '',
'search_value' => '%note%',
'expected_value' => ['LIKE' => '%note%'],
],
[
'custom_group_id' => $customGroup['id'],
'data_type' => 'String',
'html_type' => 'Autocomplete-Select',
'default_value' => '',
'search_value' => 'R,Y',
'expected_value' => ['IN' => ['R', 'Y']],
'option_values' => [
[
'label' => 'Red',
'value' => 'R',
'weight' => 1,
'is_active' => 1,
],
[
'label' => 'Yellow',
'value' => 'Y',
'weight' => 2,
'is_active' => 1,
],
[
'label' => 'Green',
'value' => 'G',
'weight' => 3,
'is_active' => 1,
],
],
],
] as $field) {
$id = $this->customFieldCreate($field)['id'];
$customKey = 'custom_' . $id;
$params[$customKey] = $field['search_value'];
CRM_Core_BAO_CustomValue::fixCustomFieldValue($params);
$this->assertEquals($params[$customKey], $field['expected_value'], 'Checking the returned value of type ' . $field['data_type']);

// delete created custom field
$this->customFieldDelete($id);
}

$this->customFieldDelete($customField['id']);
$this->customGroupDelete($customGroup['id']);
}

Expand Down

0 comments on commit caec1f1

Please sign in to comment.