3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class generates form components for Address Section.
37 class CRM_Admin_Form_Preferences_Address
extends CRM_Admin_Form_Preferences
{
39 protected $_settings = [
40 'address_options' => CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
41 'address_format' => CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
42 'mailing_format' => CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
43 'hideCountryMailingLabels' => CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
44 'address_standardization_provider' => CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
,
45 'address_standardization_userid' => CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
,
46 'address_standardization_url' => CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
,
50 * Build the form object.
52 public function buildQuickForm() {
53 $this->applyFilter('__ALL__', 'trim');
55 $this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
57 //get the tokens for Mailing Label field
58 $tokens = CRM_Core_SelectValues
::contactTokens();
59 $this->assign('tokens', CRM_Utils_Token
::formatTokensForDisplay($tokens));
61 parent
::buildQuickForm();
69 public static function formRule($fields) {
70 $p = $fields['address_standardization_provider'];
71 $u = $fields['address_standardization_userid'];
72 $w = $fields['address_standardization_url'];
74 // make sure that there is a value for all of them
75 // if any of them are set
78 if (!($p && $u && $w)) {
79 $errors['_qf_default'] = ts('You must provide values for all three Address Standardization fields.');
88 * Process the form submission.
90 public function postProcess() {
91 if ($this->_action
== CRM_Core_Action
::VIEW
) {
95 $this->_params
= $this->controller
->exportValues($this->_name
);
96 $addressOptions = CRM_Core_OptionGroup
::values('address_options', TRUE);
98 // check if county option has been set
99 if (CRM_Utils_Array
::value($addressOptions['County'], $this->_params
['address_options'])) {
100 $countyCount = CRM_Core_DAO
::singleValueQuery("SELECT count(*) FROM civicrm_county");
101 if ($countyCount < 10) {
102 CRM_Core_Session
::setStatus(ts('You have enabled the County option. Please ensure you populate the county table in your CiviCRM Database. You can find extensions to populate counties in the <a %1>CiviCRM Extensions Directory</a>.', array(1 => 'href="' . CRM_Utils_System
::url('civicrm/admin/extensions', array('reset' => 1), TRUE, 'extensions-addnew') . '"')),
103 ts('Populate counties'),
109 // check that locale supports address parsing
111 CRM_Utils_Array
::value($addressOptions['Street Address Parsing'], $this->_params
['address_options']) &&
112 !CRM_Core_BAO_Address
::isSupportedParsingLocale()
114 $config = CRM_Core_Config
::singleton();
115 $locale = $config->lcMessages
;
116 CRM_Core_Session
::setStatus(ts('Default locale (%1) does not support street parsing. en_US locale will be used instead.', [1 => $locale]), ts('Unsupported Locale'), 'alert');
119 $this->postProcessCommon();