State/Province required-ness fix if Country doesn't contain it on CiviProfile
[civicrm-core.git] / CRM / Profile / Form.php
index 5db324da76aa45708d14fb2fac9182280a5d96cd..c55b089dd8471f93b734fee1e6810e10a5fd568e 100644 (file)
@@ -505,7 +505,8 @@ class CRM_Profile_Form extends CRM_Core_Form {
           }
         }
       }
-    } else {
+    }
+    else {
       foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
           $htmlType = $field['html_type'];
@@ -522,9 +523,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
           if ($htmlType == 'File') {
             $entityId = $this->_id;
-            if (CRM_Utils_Array::value('field_type', $field) == 'Activity' &&
-              $this->_activityId
-            ) {
+            if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
               $entityId = $this->_activityId;
             }
             $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
@@ -564,6 +563,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
       $this->assign("imageThumbWidth", $imageThumbWidth);
       $this->assign("imageThumbHeight", $imageThumbHeight);
       $this->assign("imageURL", $this->_defaults['image_URL']);
+      $this->removeFileRequiredRules('image_URL');
     }
 
     if (array_key_exists('contact_sub_type', $this->_defaults) &&
@@ -680,6 +680,21 @@ class CRM_Profile_Form extends CRM_Core_Form {
       return FALSE;
     }
 
+    if (count($this->_submitValues)) {
+      $location_type_id = null;
+      foreach ($this->_fields as $field) {
+        if (!empty($field['location_type_id'])) {
+          $location_type_id = $field['location_type_id'];
+        }
+        if (array_key_exists("country-{$location_type_id}", $this->_fields) &&
+          array_key_exists("state_province-{$location_type_id}", $this->_fields) &&
+          !empty($this->_submitValues["country-{$location_type_id}"])) {
+          $this->_fields["state_province-{$location_type_id}"]['is_required'] =
+            CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$location_type_id}");
+        }
+      }
+    }
+
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
@@ -1317,6 +1332,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
       $params['contactID'] = $this->_id;
       if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) {
         CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error');
+        CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']);
         $transaction->rollback();
         return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create',
             'reset=1&gid=' . $this->_gid