From: Seamus Lee Date: Fri, 19 Aug 2016 09:38:19 +0000 (+1000) Subject: 2nd attempt at capitalising country names, Also add a setting allowing users to hide... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=04c56532961fb72d731fe509b6c67569d788b6c3;p=civicrm-core.git 2nd attempt at capitalising country names, Also add a setting allowing users to hide country if country matches that of domain country --- diff --git a/CRM/Admin/Form/Preferences.php b/CRM/Admin/Form/Preferences.php index c39d615a50..c3b1600eb0 100644 --- a/CRM/Admin/Form/Preferences.php +++ b/CRM/Admin/Form/Preferences.php @@ -174,6 +174,10 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form { $this->addRadio($fieldName, $fieldValue['title'], $options, NULL, '  '); break; + case 'YesNo': + $this->addRadio($fieldName, $fieldValue['title'], array(0 => 'No', 1 => 'Yes'), NULL, '  '); + break; + case 'checkboxes': $options = array_flip(CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE)); $newOptions = array(); @@ -269,6 +273,7 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form { case 'text': case 'select': case 'radio': + case 'YesNo': case 'entity_reference': $this->_config->$settingName = CRM_Utils_Array::value($settingName, $this->_params); break; diff --git a/CRM/Admin/Form/Preferences/Address.php b/CRM/Admin/Form/Preferences/Address.php index 09ce28cd68..3443291ff5 100644 --- a/CRM/Admin/Form/Preferences/Address.php +++ b/CRM/Admin/Form/Preferences/Address.php @@ -63,25 +63,30 @@ class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { 'description' => NULL, 'weight' => 3, ), + 'hideCountryMailingLabels' => array( + 'html_type' => 'YesNo', + 'title' => 'Hide Country in Mailing Labels when same as domain country', + 'weight' => 4, + ), ), CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => array( 'address_standardization_provider' => array( 'html_type' => 'select', 'title' => ts('Provider'), 'option_values' => $addrProviders, - 'weight' => 4, + 'weight' => 5, ), 'address_standardization_userid' => array( 'html_type' => 'text', 'title' => ts('User ID'), 'description' => NULL, - 'weight' => 5, + 'weight' => 6, ), 'address_standardization_url' => array( 'html_type' => 'text', 'title' => ts('Web Service URL'), 'description' => NULL, - 'weight' => 6, + 'weight' => 7, ), ), ); @@ -102,6 +107,7 @@ class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { $defaults['address_format'] = $this->_config->address_format; $defaults['mailing_format'] = $this->_config->mailing_format; + $defaults['hideCountryMailingLabels'] = $this->_config->hideCountryMailingLabels; parent::cbsDefaultValues($defaults); diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 45a100bde4..878390fb09 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -94,6 +94,21 @@ class CRM_Utils_Address { } } + if ($mailing && !empty($fields['country'])) { + if (Civi::settings()->get('hideCountryMailingLabels')) { + $domain = CRM_Core_BAO_Domain::getDomain(); + $domainLocation = CRM_Core_Location::getValues(array('contact_id' => $domain->contact_id)); + $domainAddress = $domainLocation['address'][1]; + $domainCountryId = $domainAddress['country_id']; + if ($fields['country'] == CRM_Core_PseudoConstant::country($domainCountryId)) { + $fields['country'] = NULL; + } + } + else { + $fields['country'] = strtoupper($fields['country']); + } + } + $contactName = CRM_Utils_Array::value('display_name', $fields); if (!$individualFormat) { if (isset($fields['id'])) { diff --git a/settings/Address.setting.php b/settings/Address.setting.php index e5e7824fde..79def1b6cb 100644 --- a/settings/Address.setting.php +++ b/settings/Address.setting.php @@ -79,4 +79,18 @@ return array( 'help_text' => 'Web Service URL', 'validate_callback' => 'CRM_Utils_Rule::url', ), + 'hideCountryMailingLabels' => array( + 'group_name' => 'Address Preferences', + 'group' => 'address', + 'name' => 'hideCountryMailingLabels', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => 0, + 'add' => '4.7', + 'title' => 'Hide Country in Mailing Labels when same as domain country', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Do not display the country field in mailing labels when the country is the same as that of the domain', + 'help_text' => NULL, + ), ); diff --git a/templates/CRM/Admin/Form/Preferences/Address.tpl b/templates/CRM/Admin/Form/Preferences/Address.tpl index 52303c4e5a..ccd6f9e860 100644 --- a/templates/CRM/Admin/Form/Preferences/Address.tpl +++ b/templates/CRM/Admin/Form/Preferences/Address.tpl @@ -38,6 +38,12 @@ {ts}Content and format for mailing labels.{/ts} + + {$form.hideCountryMailingLabels.label} + {$form.hideCountryMailingLabels.html} + + +

{ts}Address Display{/ts}