Filter groups according to included profiles
[civicrm-core.git] / CRM / Event / Form / Registration / Confirm.php
index 75e66c5644f5ec1b1f7ee5ee3760318502b02cb8..8de867441b6747861cc6114f4c8419c6666f331c 100644 (file)
@@ -1104,8 +1104,23 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
         unset($params['contact_id']);
       }
 
-      // sudoman hack: re-insert filtered group memberships
-      $params = CRM_Contact_Form_Edit_TagsAndGroups::reInsertFilteredGroupMemberships($form->get('id'), 'event', $contactID, TRUE, $params);
+      // sudoman hack: get profile ids before re-inserting filtered group memberships
+      foreach (['custom_pre_id', 'custom_post_id'] as $which_profile) {
+
+        $profile_ids = $form->get('values')[$which_profile];
+
+        // some pages can have multiple profiles
+        if (!is_array($profile_ids)) {
+          $all_profile_ids[] = $profile_ids;
+        } else {
+          $all_profile_ids = array_merge($all_profile_ids, $profile_ids);
+        }
+      }
+
+      // sudoman hack: continues from above: re-insert filtered group memberships
+      if (isset($fields['group'])) {
+        $params = CRM_Contact_Form_Edit_TagsAndGroups::reInsertFilteredGroupMemberships($all_profile_ids, $contactID, TRUE, $params);
+      }
 
       $contactID = CRM_Contact_BAO_Contact::createProfileContact(
         $params,