From: Coleman Watts Date: Mon, 6 Oct 2014 19:58:55 +0000 (-0400) Subject: CRM-13981 - Fix default value bug introduced in 133e2c9 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9c80939e025d9366e1f694295b415f24c618135e;p=civicrm-core.git CRM-13981 - Fix default value bug introduced in 133e2c9 This commit cleans up a useless foreach loop that didn't do anything (the conditional would always evaluate to TRUE) and fixes a bug with setting default values: It seems that with Quickform, calling $form->setDefults with $defaults['foo']['bar'] = $value is "almost" equivalent to $defaults["foo[bar]"] = $value but with one key difference: the latter always trumps the former. So because the buildProfile function uses the latter method to set country default value to defaultContactCountry (e.g. United States), that would always override the "correct" default value which is set here. --- diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 8289a514b9..baf0904625 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -576,17 +576,18 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } $defaults = array(); - $fields = array(); - foreach ($this->_fields as $name => $dontCare) { - if ($name != 'onbehalf' || $name != 'honor') { - $fields[$name] = 1; - } - } + $fields = array_fill_keys(array_keys($this->_fields), 1); $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1; $contact = $this->_params; foreach ($fields as $name => $dontCare) { - if (isset($contact[$name])) { + // Recursively set defaults for nested fields + if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) { + foreach ($contact[$name] as $fieldName => $fieldValue) { + $defaults["{$name}[{$fieldName}]"] = $fieldValue; + } + } + elseif (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time";