Skip to content
Snippets Groups Projects
Commit 1e990036 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

Merge pull request #1917 from monishdeb/CRM-11881

CRM-11881 fix - State/Province required-ness fix if Country doesn't contain it on CiviProfile
parents 30a6da05 57d9b2d0
Branches
Tags
No related merge requests found
......@@ -73,7 +73,7 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
// renewal case - membership being renewed may or may not be for organization
if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
// if _membershipContactID belongs to employers list, we can say:
// if _membershipContactID belongs to employers list, we can say:
$form->_relatedOrganizationFound = TRUE;
}
} else if (!empty($form->_employers)) {
......@@ -162,6 +162,14 @@ class CRM_Contribute_Form_Contribution_OnBehalfOf {
}
$stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
if (count($form->_submitValues)) {
$locationTypeId = $field['location_type_id'];
if (!empty($form->_submitValues['onbehalf']["country-{$locationTypeId}"]) &&
$prefixName == "state_province") {
$field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($form, "country-{$locationTypeId}", TRUE);
}
}
}
elseif (in_array($prefixName, array(
'organization_name', 'email')) &&
......
......@@ -704,6 +704,25 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
if ($prefixName == "state_province") {
if ($onBehalf) {
//CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
//as already done during Contribution registration via onBehalf's quickForm
$field['is_required'] = FALSE;
}
else {
if (count($this->_submitValues)) {
$locationTypeId = $field['location_type_id'];
if (array_key_exists("country-{$locationTypeId}", $fields) &&
array_key_exists("state_province-{$locationTypeId}", $fields) &&
!empty($this->_submitValues["country-{$locationTypeId}"])) {
$field['is_required'] =
CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
}
}
}
}
}
if ($onBehalf) {
......
......@@ -111,7 +111,7 @@ class CRM_Core_Payment_Form {
'attributes' => array(
'' => ts('- select -')) +
CRM_Core_PseudoConstant::stateProvince(),
'is_required' => self::checkRequiredStateProvince($form),
'is_required' => self::checkRequiredStateProvince($form, "billing_country_id-{$bltID}"),
);
$form->_paymentFields["billing_postal_code-{$bltID}"] = array(
......@@ -436,13 +436,28 @@ class CRM_Core_Payment_Form {
/**
* function to return state/province is_required = true/false
*
* @param obj $form: Form object
* @param string $name: Country index name on $_submitValues array
* @param bool $onBehalf: Is 'On Behalf Of' profile?
*
* @return bool
* TRUE/FALSE for is_required if country consist/not consist of state/province respectively
* @static
*/
static function checkRequiredStateProvince($form) {
static function checkRequiredStateProvince($form, $name, $onBehalf = FALSE) {
// If selected country has possible values for state/province mark the
// state/province field as required.
$config = CRM_Core_Config::singleton();
$stateProvince = new CRM_Core_DAO_StateProvince();
$stateProvince->country_id = CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $form->_submitValues);
if ($onBehalf) {
$stateProvince->country_id = CRM_Utils_Array::value($name, $form->_submitValues['onbehalf']);
}
else {
$stateProvince->country_id = CRM_Utils_Array::value($name, $form->_submitValues);
}
$limitCountryId = $stateProvince->country_id;
if ($stateProvince->count() > 0) {
// check that the state/province data is not excluded by a
......@@ -454,7 +469,6 @@ class CRM_Core_Payment_Form {
$limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
}
$limitCountryId = CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $form->_submitValues);
if ($limitCountryId && in_array($limitCountryId, $limitIds)) {
return TRUE;
}
......
......@@ -680,6 +680,21 @@ class CRM_Profile_Form extends CRM_Core_Form {
return FALSE;
}
if (count($this->_submitValues)) {
$locationTypeId = null;
foreach ($this->_fields as $field) {
if (!empty($field['location_type_id'])) {
$locationTypeId = $field['location_type_id'];
}
if (array_key_exists("country-{$locationTypeId}", $this->_fields) &&
array_key_exists("state_province-{$locationTypeId}", $this->_fields) &&
!empty($this->_submitValues["country-{$locationTypeId}"])) {
$this->_fields["state_province-{$locationTypeId}"]['is_required'] =
CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
}
}
}
$this->assign('id', $this->_id);
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment