From: eileen Date: Mon, 4 Feb 2019 02:06:37 +0000 (+1300) Subject: dev/core#691 Make default country optional on setting form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1c8738dd4f210e403aec7c7af1792dca5c51049e;p=civicrm-core.git dev/core#691 Make default country optional on setting form This includes removing the default of 'United States'.... ahem! --- diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index f124ef72e6..81fb55fa08 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -177,6 +177,12 @@ trait CRM_Admin_Form_SettingTrait { $options = civicrm_api3('Setting', 'getoptions', [ 'field' => $setting, ])['values']; + if ($props['html_type'] === 'Select' && isset($props['is_required']) && $props['is_required'] === FALSE && !isset($options[''])) { + // If the spec specifies the field is not required add a null option. + // Why not if empty($props['is_required']) - basically this has been added to the spec & might not be set to TRUE + // when it is true. + $options = ['' => ts('None')] + $options; + } } if ($props['type'] === 'Boolean') { $options = [$props['title'] => $props['name']]; diff --git a/settings/Localization.setting.php b/settings/Localization.setting.php index 54f05b2971..3d15ee0f22 100644 --- a/settings/Localization.setting.php +++ b/settings/Localization.setting.php @@ -156,11 +156,11 @@ return array( 'html_attributes' => array( //'class' => 'crm-select2', ), - 'default' => '1228', 'add' => '4.4', 'title' => 'Default Country', 'is_domain' => 1, 'is_contact' => 0, + 'is_required' => FALSE, 'description' => 'This value is selected by default when adding a new contact address.', 'help_text' => NULL, 'pseudoconstant' => array( diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 0f059129d6..e1312ea1d8 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -509,6 +509,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * CRM-19888 default country should be used if ambigous. */ public function testImportAmbiguousStateCountry() { + $this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]); $countries = CRM_Core_PseudoConstant::country(FALSE, FALSE); $this->callAPISuccess('Setting', 'create', array('countryLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)))); $this->callAPISuccess('Setting', 'create', array('provinceLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)))); diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index d7551c484c..ce7af69fdf 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -198,7 +198,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { * Get Billing empty contact - this will return generic defaults */ public function testProfileGetBillingEmptyContact() { - + $this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]); $params = array( 'profile_id' => array('Billing'), );