Skip to content

Commit

Permalink
Merge pull request #13004 from eileenmcnaughton/setting_address
Browse files Browse the repository at this point in the history
Fix e-notices on Address settings page, convert YesNo field
  • Loading branch information
eileenmcnaughton authored Oct 30, 2018
2 parents 880f730 + c7cd4e2 commit a9ab14a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 99 deletions.
92 changes: 10 additions & 82 deletions CRM/Admin/Form/Preferences/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,84 +35,16 @@
* This class generates form components for Address Section.
*/
class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences {
public function preProcess() {

CRM_Utils_System::setTitle(ts('Settings - Addresses'));

// Address Standardization
$addrProviders = array(
'' => '- select -',
) + CRM_Core_SelectValues::addressProvider();

$this->_varNames = array(
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array(
'address_options' => array(
'html_type' => 'checkboxes',
'title' => ts('Address Fields'),
'weight' => 1,
),
'address_format' => array(
'html_type' => 'textarea',
'title' => ts('Display Format'),
'description' => NULL,
'weight' => 2,
),
'mailing_format' => array(
'html_type' => 'textarea',
'title' => ts('Mailing Label Format'),
'description' => NULL,
'weight' => 3,
),
'hideCountryMailingLabels' => array(
'html_type' => 'YesNo',
'title' => ts('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' => 5,
),
'address_standardization_userid' => array(
'html_type' => 'text',
'title' => ts('User ID'),
'description' => NULL,
'weight' => 6,
),
'address_standardization_url' => array(
'html_type' => 'text',
'title' => ts('Web Service URL'),
'description' => NULL,
'weight' => 7,
),
),
);

parent::preProcess();
}

/**
* @return array
*/
public function setDefaultValues() {
$defaults = array();
$defaults['address_standardization_provider'] = $this->_config->address_standardization_provider;
$defaults['address_standardization_userid'] = $this->_config->address_standardization_userid;
$defaults['address_standardization_url'] = $this->_config->address_standardization_url;

$this->addressSequence = isset($newSequence) ? $newSequence : "";

$defaults['address_format'] = $this->_config->address_format;
$defaults['mailing_format'] = $this->_config->mailing_format;
$defaults['hideCountryMailingLabels'] = $this->_config->hideCountryMailingLabels;

parent::cbsDefaultValues($defaults);

return $defaults;
}
protected $_settings = [
'address_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'address_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'mailing_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'hideCountryMailingLabels' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'address_standardization_provider' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME,
'address_standardization_userid' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME,
'address_standardization_url' => CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME,
];

/**
* Build the form object.
Expand Down Expand Up @@ -142,13 +74,9 @@ public static function formRule($fields) {
// make sure that there is a value for all of them
// if any of them are set
if ($p || $u || $w) {
if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) {
$errors['_qf_default'] = ts('Address Standardization features require PHP version 5 or greater.');
return $errors;
}

if (!($p && $u && $w)) {
$errors['_qf_default'] = ts('You must provide values for all three Address Standarization fields.');
$errors['_qf_default'] = ts('You must provide values for all three Address Standardization fields.');
return $errors;
}
}
Expand Down
3 changes: 3 additions & 0 deletions CRM/Admin/Form/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ protected function addFieldsDefinedInSettingsMetadata() {
elseif ($add === 'addEntityRef') {
$this->$add($setting, ts($props['title']), $props['entity_reference_options']);
}
elseif ($add === 'addYesNo' && ($props['type'] === 'Boolean')) {
$this->addRadio($setting, ts($props['title']), array(1 => 'Yes', 0 => 'No'), NULL, '  ');
}
else {
$this->$add($setting, ts($props['title']), $options);
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/SelectValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public static function geoProvider() {
public static function addressProvider() {
static $addr = NULL;
if (!$addr) {
$addr = CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate'));
$addr = array_merge(['' => '- select -'], CRM_Utils_System::getPluginList('CRM/Utils/Address', '.php', array('BatchUpdate')));
}
return $addr;
}
Expand Down
4 changes: 4 additions & 0 deletions CRM/Utils/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ public static function query($query) {
* @return bool
*/
public static function url($url) {
if (!$url) {
// If this is required then that should be checked elsewhere - here we are not assuming it is required.
return TRUE;
}
if (preg_match('/^\//', $url)) {
// allow relative URL's (CRM-15598)
$url = 'http://' . $_SERVER['HTTP_HOST'] . $url;
Expand Down
20 changes: 10 additions & 10 deletions settings/Address.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/*

/**
* Settings metadata file
*/
return array(
Expand All @@ -41,10 +40,11 @@
'group' => 'address',
'name' => 'address_standardization_provider',
'type' => 'String',
'html_type' => 'Select',
'html_type' => 'select',
'default' => NULL,
'add' => '4.1',
'title' => 'Address Standardization Provider.',
'title' => ts('Address Standardization Provider.'),
'pseudoconstant' => ['callback' => 'CRM_Core_SelectValues::addressProvider'],
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
Expand All @@ -55,10 +55,10 @@
'group' => 'address',
'name' => 'address_standardization_userid',
'type' => 'String',
'html_type' => 'Text',
'html_type' => 'text',
'default' => NULL,
'add' => '4.1',
'title' => 'Web service user ID',
'title' => ts('Provider service user ID'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
Expand All @@ -69,10 +69,10 @@
'group' => 'address',
'name' => 'address_standardization_url',
'type' => 'Text',
'html_type' => 'Text',
'html_type' => 'text',
'default' => NULL,
'add' => '4.1',
'title' => 'Web Service URL',
'title' => ts('Provider Service URL'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
Expand All @@ -87,7 +87,7 @@
'quick_form_type' => 'YesNo',
'default' => 0,
'add' => '4.7',
'title' => 'Hide Country in Mailing Labels when same as domain country',
'title' => ts('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',
Expand Down
13 changes: 7 additions & 6 deletions settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,28 @@
'group' => 'core',
'name' => 'address_options',
'type' => 'String',
'html_type' => 'Text',
'html_type' => 'checkboxes',
'pseudoconstant' => array(
'optionGroupName' => 'address_options',
),
'default' => '123456891011',
'add' => '4.1',
'title' => 'Addressing Options',
'title' => ts('Address Fields'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
'help_text' => NULL,
'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND,
),
'address_format' => array(
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'address_format',
'type' => 'String',
'html_type' => 'TextArea',
'html_type' => 'textarea',
'default' => "{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}",
'add' => '4.1',
'title' => 'Address Format',
'title' => ts('Address Display Format'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
Expand All @@ -143,10 +144,10 @@
'group' => 'core',
'name' => 'mailing_format',
'type' => 'String',
'html_type' => 'Text',
'html_type' => 'textarea',
'default' => "{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.supplemental_address_3}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}",
'add' => '4.1',
'title' => 'Mailing Format',
'title' => ts('Mailing Label Format'),
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
Expand Down

0 comments on commit a9ab14a

Please sign in to comment.