CRM-13726 includes PR 1934 plus fix from https://github.com/eileenmcnaughton/civicrm...
authorDave Greenberg <dave@civicrm.org>
Mon, 13 Jan 2014 20:27:54 +0000 (12:27 -0800)
committerDave Greenberg <dave@civicrm.org>
Mon, 13 Jan 2014 20:27:54 +0000 (12:27 -0800)
----------------------------------------
* CRM-13726: Only show 'billing addres is same as above' checkbox if there is an address above
  http://issues.civicrm.org/jira/browse/CRM-13726

CRM/Contribute/Form/Contribution/Main.php
CRM/Core/BAO/UFField.php
CRM/Event/Form/Registration/Register.php

index 68918da67f3ac9f4b627c5f1845fee03545f5c33..08e3a1dc04db651247f0f7946af5976abd17f0d3 100644 (file)
@@ -337,10 +337,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
     $this->buildCustom($this->_values['custom_post_id'], 'customPost');
 
-    if (!empty($this->_fields)) {
+    if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
       $profileAddressFields = array();
       foreach ($this->_fields as $key => $value) {
-        CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields);
+        CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id']));
       }
       $this->set('profileAddressFields', $profileAddressFields);
     }
index fb779f7add740783f8e033796890ef8d1beb50c7..e4baabe332852abc74cb65d56b2b47572d5de886 100644 (file)
@@ -788,13 +788,15 @@ SELECT  id
    * http://issues.civicrm.org/jira/browse/CRM-5869
    *
    * @param string $key Field key - e.g. street_address-Primary, first_name
-   * @param $profileAddressFields
-   * @params array $profileAddressFields array of profile fields that relate to address fields
+   * @param array $profileAddressFields array of profile fields that relate to address fields
+   * @param array $profileFilter filter to apply to profile fields - expected usage is to only fill based on
+   * the bottom profile per CRM-13726
    */
-  static function assignAddressField($key, &$profileAddressFields) {
+  static function assignAddressField($key, &$profileAddressFields, $profileFilter) {
     $billing_id = CRM_Core_BAO_LocationType::getBilling();
     list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
 
+    $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name')));
     //check for valid fields ( fields that are present in billing block )
     $validBillingFields = array(
       'first_name',
@@ -807,8 +809,15 @@ SELECT  id
       'postal_code',
       'country'
     );
+    $validProfileFields = array();
 
-    if (!in_array($prefixName, $validBillingFields)) {
+    foreach ($profileFields['values'] as $field) {
+      if(in_array($field['field_name'], $validBillingFields)) {
+        $validProfileFields[] = $field['field_name'];
+      }
+    }
+
+    if (!in_array($prefixName, $validProfileFields) ) {
       return;
     }
 
index 3e785fdf571b0396327a3b4cd001a07272e01fb5..306a5bee075d9b51ea747ab381edca33a257eda1 100644 (file)
@@ -321,11 +321,10 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
     $this->buildCustom($this->_values['custom_post_id'], 'customPost');
 
-    if (!empty($this->_fields)) {
+    if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
       $profileAddressFields = array();
       foreach ($this->_fields as $key => $value) {
-        CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields);
-      }
+        CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id']));      }
       $this->set('profileAddressFields', $profileAddressFields);
     }