Filter groups according to included profiles
[civicrm-core.git] / CRM / Event / Form / Registration / Confirm.php
index c91e89a443d53abeee2625a9957b9552cc93484b..8de867441b6747861cc6114f4c8419c6666f331c 100644 (file)
@@ -1104,6 +1104,24 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
         unset($params['contact_id']);
       }
 
+      // 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,
         $fields,