From c7cd4e2c3354d793311dfeb0c11f919069e8187b Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 25 Oct 2018 09:56:10 +1300 Subject: [PATCH] Fix e-notices on Address settings page, convert YesNo field This fixes enotices & also does our first preferences conversion of a YesNo / Radio field --- CRM/Admin/Form/Preferences/Address.php | 92 +++----------------------- CRM/Admin/Form/SettingTrait.php | 3 + CRM/Core/SelectValues.php | 2 +- CRM/Utils/Rule.php | 4 ++ settings/Address.setting.php | 20 +++--- settings/Core.setting.php | 13 ++-- 6 files changed, 35 insertions(+), 99 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Address.php b/CRM/Admin/Form/Preferences/Address.php index c0a1177099..2058192e97 100644 --- a/CRM/Admin/Form/Preferences/Address.php +++ b/CRM/Admin/Form/Preferences/Address.php @@ -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. @@ -142,13 +74,9 @@ class CRM_Admin_Form_Preferences_Address extends CRM_Admin_Form_Preferences { // 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; } } diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index fafae4f4d6..ab9328af3f 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -188,6 +188,9 @@ trait CRM_Admin_Form_SettingTrait { 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); } diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index c34c51619a..44e5bdb854 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -466,7 +466,7 @@ class CRM_Core_SelectValues { 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; } diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index 2bc78c243e..ee5661d4f3 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -229,6 +229,10 @@ class CRM_Utils_Rule { * @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; diff --git a/settings/Address.setting.php b/settings/Address.setting.php index 6ea9ea29f9..b7384a61f3 100644 --- a/settings/Address.setting.php +++ b/settings/Address.setting.php @@ -29,10 +29,9 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2017 - * $Id$ - * */ -/* + +/** * Settings metadata file */ return array( @@ -41,10 +40,11 @@ return array( '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, @@ -55,10 +55,10 @@ return array( '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, @@ -69,10 +69,10 @@ return array( '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, @@ -87,7 +87,7 @@ return array( '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', diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 996b005c3a..47b6ad439c 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -112,27 +112,28 @@ return array( '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, @@ -143,10 +144,10 @@ return array( '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, -- 2.25.1