$this->buildCustom($this->_values['custom_pre_id'], 'customPre');
$this->buildCustom($this->_values['custom_post_id'], 'customPost');
- if (!empty($this->_fields)) {
+ if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
$profileAddressFields = array();
foreach ($this->_fields as $key => $value) {
- CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields);
+ CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id']));
}
$this->set('profileAddressFields', $profileAddressFields);
}
* http://issues.civicrm.org/jira/browse/CRM-5869
*
* @param string $key Field key - e.g. street_address-Primary, first_name
- * @param $profileAddressFields
- * @params array $profileAddressFields array of profile fields that relate to address fields
+ * @param array $profileAddressFields array of profile fields that relate to address fields
+ * @param array $profileFilter filter to apply to profile fields - expected usage is to only fill based on
+ * the bottom profile per CRM-13726
*/
- static function assignAddressField($key, &$profileAddressFields) {
+ static function assignAddressField($key, &$profileAddressFields, $profileFilter) {
$billing_id = CRM_Core_BAO_LocationType::getBilling();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
+ $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name')));
//check for valid fields ( fields that are present in billing block )
$validBillingFields = array(
'first_name',
'postal_code',
'country'
);
+ $validProfileFields = array();
- if (!in_array($prefixName, $validBillingFields)) {
+ foreach ($profileFields['values'] as $field) {
+ if(in_array($field['field_name'], $validBillingFields)) {
+ $validProfileFields[] = $field['field_name'];
+ }
+ }
+
+ if (!in_array($prefixName, $validProfileFields) ) {
return;
}
$this->buildCustom($this->_values['custom_pre_id'], 'customPre');
$this->buildCustom($this->_values['custom_post_id'], 'customPost');
- if (!empty($this->_fields)) {
+ if (!empty($this->_fields) && !empty($this->_values['custom_pre_id'])) {
$profileAddressFields = array();
foreach ($this->_fields as $key => $value) {
- CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields);
- }
+ CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id'])); }
$this->set('profileAddressFields', $profileAddressFields);
}