From 1ad7255fe597877f08bc4ff587628f323004a709 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Tue, 19 Aug 2014 16:06:29 -0700 Subject: [PATCH] CRM-15118 - potential replacement for https://github.com/civicrm/civicrm-core/pull/3872 which did not work in my testing (billing block never hideable). ---------------------------------------- * CRM-15118: https://issues.civicrm.org/jira/browse/CRM-15118 --- CRM/Core/BAO/UFField.php | 12 +++++++++++- templates/CRM/Core/BillingBlock.tpl | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/UFField.php b/CRM/Core/BAO/UFField.php index 22bcf67496..6c1189caca 100644 --- a/CRM/Core/BAO/UFField.php +++ b/CRM/Core/BAO/UFField.php @@ -803,13 +803,15 @@ SELECT id * @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 + * + * @return bool Can the address block be hidden safe in the knowledge all fields are elsewhere collected (see CRM-15118) */ 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', 'options' => array( + array('is_active' => 1, 'return' => 'field_name, is_required', 'options' => array( 'limit' => 0, )) )); @@ -825,12 +827,17 @@ SELECT id 'postal_code', 'country' ); + $requiredBillingFields = array_diff($validBillingFields, array('middle_name','supplemental_address_1')); $validProfileFields = array(); + $requiredProfileFields = array(); foreach ($profileFields['values'] as $field) { if(in_array($field['field_name'], $validBillingFields)) { $validProfileFields[] = $field['field_name']; } + if ($field['is_required']) { + $requiredProfileFields[] = $field['field_name']; + } } if (!in_array($prefixName, $validProfileFields) ) { @@ -852,6 +859,9 @@ SELECT id ) { $profileAddressFields[$prefixName] = $index; } + + $potentiallyMissingRequiredFields = array_diff($requiredBillingFields, $requiredProfileFields); + CRM_Core_Resources::singleton()->addSetting(array('billing' => array('billingProfileIsHideable' => empty($potentiallyMissingRequiredFields)))); } /** diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index d3d2f91d00..53cab5ec94 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -226,7 +226,9 @@ CRM.$(function($) { } if(checked) { $('#billingcheckbox').prop('checked', true); - $('.billing_name_address-group').hide(); + if (CRM.billing.billingProfileIsHideable) { + $('.billing_name_address-group').hide(); + } } // onchange handlers for non-billing fields @@ -264,7 +266,9 @@ CRM.$(function($) { // toggle show/hide $('#billingcheckbox').click(function(){ if(this.checked) { - $('.billing_name_address-group').hide(200); + if (CRM.billing.billingProfileIsHideable) { + $('.billing_name_address-group').hide(200); + } // copy all values for(var id in input_ids) { -- 2.25.1