+ /**
+ * Set a message warning the user about putting country first to render states, if required.
+ *
+ * @param string $fieldName
+ * @param int $locationTypeID
+ * @param int $weight
+ * @param int $ufGroupID
+ */
+ protected function setMessageIfCountryNotAboveState($fieldName, $locationTypeID, $weight, $ufGroupID) {
+ $message = ts('For best results, the Country field should precede the State-Province field in your Profile form. You can use the up and down arrows on field listing page for this profile to change the order of these fields or manually edit weight for Country/State-Province Field.');
+
+ if (in_array($fieldName, array(
+ 'country',
+ 'state_province',
+ )) && count(CRM_Core_Config::singleton()->countryLimit) > 1
+ ) {
+ // get state or country field weight if exists
+ $ufFieldDAO = new CRM_Core_DAO_UFField();
+ $ufFieldDAO->field_name = ($fieldName == 'state_province' ? 'country' : 'state_province');
+ $ufFieldDAO->location_type_id = $locationTypeID;
+ $ufFieldDAO->uf_group_id = $ufGroupID;
+
+ if ($ufFieldDAO->find(TRUE)) {
+ if ($ufFieldDAO->field_name == 'country' && $ufFieldDAO->weight > $weight) {
+ CRM_Core_Session::setStatus($message);
+ }
+ elseif ($ufFieldDAO->field_name == 'state_province' && $ufFieldDAO->weight < $weight) {
+ CRM_Core_Session::setStatus($message);
+ }
+ }
+ }
+ }
+