Fix event merging profiles together
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Nov 2023 02:37:01 +0000 (15:37 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 21 Nov 2023 18:56:13 +0000 (07:56 +1300)
https://lab.civicrm.org/dev/core/-/issues/4766

CRM/Event/Form/Registration.php
templates/CRM/Event/Form/Registration/Register.tpl

index 1595d77e05a20e9cdb9f276c0c2560e964870e04..f73508bbb4c685b459bcc58f7f7db34f6d48a17a 100644 (file)
@@ -503,8 +503,11 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
    * @param string $name
    */
   public function buildCustom($id, $name) {
+    if ($name === 'customPost') {
+      $this->assign('postPageProfiles', []);
+    }
+    $this->assign($name, []);
     if (!$id) {
-      $this->assign($name, []);
       return;
     }
 
@@ -563,6 +566,16 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     ) {
       CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
     }
+    if ($name === 'customPost') {
+      $postPageProfiles = [];
+      foreach ($fields as $fieldName => $field) {
+        $postPageProfiles[$field['groupName']][$fieldName] = $field;
+      }
+      $this->assign('postPageProfiles', $postPageProfiles);
+    }
+    // We still assign the customPost in the way we used to because we haven't ruled out being
+    // used after the register form - but in the register form it is overwritten by a for-each
+    // with the smarty code.
     $this->assign($name, $fields);
     if (is_array($fields)) {
       $button = substr($this->controller->getButtonName(), -4);
index 496581b3eb526baf36c0c68383666998c3f7e998..747a74e154d313b6e6c7039d911ac20281840cf6 100644 (file)
     {/if}
 
     <div class="crm-public-form-item crm-section custom_post-section">
-      {include file="CRM/UF/Form/Block.tpl" fields=$customPost prefix=false hideFieldset=false}
+      {foreach from=$postPageProfiles item=customPost}
+        {include file="CRM/UF/Form/Block.tpl" fields=$customPost prefix=false hideFieldset=false}
+      {/foreach}
     </div>
 
     <div id="crm-submit-buttons" class="crm-submit-buttons">