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#1246 fix fatal error on search builder if a core contact type is disabled #15284

Merged
merged 1 commit into from
Sep 12, 2019
Merged
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
30 changes: 19 additions & 11 deletions CRM/Core/BAO/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ public static function buildMappingForm(&$form, $mappingType, $mappingId, $colum
);
}

$contactTypes = CRM_Contact_BAO_ContactType::basicTypes();
$fields = self::getBasicFields($mappingType);

// Unset groups, tags, notes for component export
Expand All @@ -383,14 +384,21 @@ public static function buildMappingForm(&$form, $mappingType, $mappingId, $colum
}

if ($mappingType == 'Search Builder') {
//build the common contact fields array.
// Build the common contact fields array.
$fields['Contact'] = [];
foreach ($fields['Individual'] as $key => $value) {
if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
foreach ($fields[$contactTypes[0]] as $key => $value) {
// If a field exists across all contact types, move it to the "Contact" selector
$ubiquitious = TRUE;
foreach ($contactTypes as $type) {
if (!isset($fields[$type][$key])) {
$ubiquitious = FALSE;
}
}
if ($ubiquitious) {
$fields['Contact'][$key] = $value;
unset($fields['Organization'][$key],
$fields['Household'][$key],
$fields['Individual'][$key]);
foreach ($contactTypes as $type) {
unset($fields[$type][$key]);
}
}
}
if (array_key_exists('note', $fields['Contact'])) {
Expand Down Expand Up @@ -429,7 +437,7 @@ public static function buildMappingForm(&$form, $mappingType, $mappingId, $colum
}
}

if (array_key_exists('related', $relatedMapperFields[$key])) {
if (isset($relatedMapperFields[$key]['related'])) {
unset($relatedMapperFields[$key]['related']);
}
}
Expand All @@ -451,18 +459,18 @@ public static function buildMappingForm(&$form, $mappingType, $mappingId, $colum

// since we need a hierarchical list to display contact types & subtypes,
// this is what we going to display in first selector
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
$contactTypeSelect = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
if ($mappingType == 'Search Builder') {
$contactTypes = ['Contact' => ts('Contacts')] + $contactTypes;
$contactTypeSelect = ['Contact' => ts('Contacts')] + $contactTypeSelect;
}

$sel1 = ['' => ts('- select record type -')] + $contactTypes + $compArray;
$sel1 = ['' => ts('- select record type -')] + $contactTypeSelect + $compArray;

foreach ($sel1 as $key => $sel) {
if ($key) {
// sort everything BUT the contactType which is sorted separately by
// an initial commit of CRM-13278 (check ksort above)
if (!in_array($key, ['Individual', 'Household', 'Organization'])) {
if (!in_array($key, $contactTypes)) {
asort($mapperFields[$key]);
}
$sel2[$key] = ['' => ts('- select field -')] + $mapperFields[$key];
Expand Down