CRM-19410 - Save Custom Data and Expose formrule on inline edit address form
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 28 Sep 2016 09:29:19 +0000 (14:59 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 28 Sep 2016 09:29:19 +0000 (14:59 +0530)
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Form/Inline/Address.php
CRM/Contact/Page/Inline/Address.php

index 8184822aab8be6a799277b396dfa3d6920fee7d4..158ecc13a7c1020518dba4d9ac60c108b7644771 100644 (file)
@@ -204,9 +204,7 @@ class CRM_Contact_Form_Edit_Address {
       // during contact editing : if no address is filled
       // required custom data must not produce 'required' form rule error
       // more handling done in formRule func
-      if (!$inlineEdit) {
-        CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
-      }
+      CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
 
       $template = CRM_Core_Smarty::singleton();
       $tplGroupTree = $template->get_template_vars('address_groupTree');
@@ -269,8 +267,9 @@ class CRM_Contact_Form_Edit_Address {
         }
 
         // DETACH 'required' form rule error to
-        // custom data only if address data not exists upon submission
-        if (!empty($customDataRequiredFields) && !CRM_Core_BAO_Address::dataExists($addressValues)) {
+        // custom data if address data not exists upon submission
+        // or if master address is selected
+        if (!empty($customDataRequiredFields) && (!CRM_Core_BAO_Address::dataExists($addressValues) || !empty($addressValues['master_id']))) {
           foreach ($customDataRequiredFields as $customElementName) {
             $elementName = "address[$instance][$customElementName]";
             if ($self->getElementError($elementName)) {
@@ -419,7 +418,7 @@ class CRM_Contact_Form_Edit_Address {
    * @param array $groupTree
    */
   public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
-    if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
+    if (in_array(CRM_Utils_System::getClassName($form), array('CRM_Contact_Form_Contact', 'CRM_Contact_Form_Inline_Address'))) {
       $requireOmission = NULL;
       foreach ($groupTree as $csId => $csVal) {
         // only process Address entity fields
index d7e3161d57b4afead70bcd9c32e973293d3f7175..ddf8f59f99b7eca4ae2a533635e370a09e084e0a 100644 (file)
@@ -125,6 +125,7 @@ class CRM_Contact_Form_Inline_Address extends CRM_Contact_Form_Inline {
   public function buildQuickForm() {
     parent::buildQuickForm();
     CRM_Contact_Form_Edit_Address::buildQuickForm($this, $this->_locBlockNo, TRUE, TRUE);
+    $this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'), $this);
   }
 
   /**
index b9d780c1b0e12105798b3acb5b21a7fbe24ef253..dc5f6978ae34fb5e52995584014155c977b25f11 100644 (file)
@@ -77,10 +77,14 @@ class CRM_Contact_Page_Inline_Address extends CRM_Core_Page {
           );
         }
       }
+      $idValue = $currentAddressBlock['address'][$locBlockNo]['id'];
+      if (!empty($currentAddressBlock['address'][$locBlockNo]['master_id'])) {
+        $idValue = $currentAddressBlock['address'][$locBlockNo]['master_id'];
+      }
 
       // add custom data of type address
       $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address',
-        $this, $currentAddressBlock['address'][$locBlockNo]['id']
+        $this, $idValue
       );
 
       // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.