2nd attempt at capitalising country names, Also add a setting allowing users to hide...
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 19 Aug 2016 09:38:19 +0000 (19:38 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 19 Aug 2016 09:38:19 +0000 (19:38 +1000)
CRM/Admin/Form/Preferences.php
CRM/Admin/Form/Preferences/Address.php
CRM/Utils/Address.php
settings/Address.setting.php
templates/CRM/Admin/Form/Preferences/Address.tpl

index c39d615a506c17a8d8c421691931a1d8fab16e01..c3b1600eb0683e70f8db3820c06c297036ba8963 100644 (file)
@@ -174,6 +174,10 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form {
               $this->addRadio($fieldName, $fieldValue['title'], $options, NULL, '&nbsp;&nbsp;');
               break;
 
+            case 'YesNo':
+              $this->addRadio($fieldName, $fieldValue['title'], array(0 => 'No', 1 => 'Yes'), NULL, '&nbsp;&nbsp;');
+              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;
index 09ce28cd68c6c39da54474c90035ba2b1804fa30..3443291ff573e43fc52892fc935763ed3f0cd41f 100644 (file)
@@ -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);
 
index 45a100bde416639e530c452d604d3be64d6a8a5a..878390fb09234b1abd0f54911ee76a623d2666a4 100644 (file)
@@ -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'])) {
index e5e7824fdeef7a7481e2a8136d56680832b133ab..79def1b6cbf5ee1609e328150e2ae9e462cc333c 100644 (file)
@@ -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,
+  ),
 );
index 52303c4e5ab53eefe86b35d617f94ba77e5fdcdc..ccd6f9e860a5180dce3005bd670add3116ff2dad 100644 (file)
                 <span class="description">{ts}Content and format for mailing labels.{/ts}</span>
             </td>
         </tr>
+         <tr class="crm-preferences-address-form-block-hideCountryMailingLabels">
+           <td class="label">{$form.hideCountryMailingLabels.label}
+           <td>{$form.hideCountryMailingLabels.html}
+           </td>
+        </tr>
+
       </table>
 
     <h3>{ts}Address Display{/ts}</h3>