diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index b97aa37b1295..86bbf890b1d5 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -304,7 +304,7 @@ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE } } - if (array_key_exists('group', $params)) { + if (!empty($params['group'])) { $contactIds = [$params['contact_id']]; foreach ($params['group'] as $groupId => $flag) { if ($flag == 1) { diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index b4a82118df37..e5b93f669e37 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -166,11 +166,11 @@ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldNam $contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE); if ($contactGroup) { - foreach ($contactGroup as $group) { - if ($groupElementType == 'select') { - $defaults[$fName][] = $group['group_id']; - } - else { + if ($groupElementType == 'select') { + $defaults[$fName] = implode(',', CRM_Utils_Array::collect('group_id', $contactGroup)); + } + else { + foreach ($contactGroup as $group) { $defaults[$fName . '[' . $group['group_id'] . ']'] = 1; } }