$settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
$props = $settingMetaData['values'][$setting];
if (isset($props['quick_form_type'])) {
+ if (isset($props['pseudoconstant'])) {
+ $options = civicrm_api3('Setting', 'getoptions', array(
+ 'field' => $setting,
+ ));
+ }
+ else {
+ $options = NULL;
+ }
+
$add = 'add' . $props['quick_form_type'];
if ($add == 'addElement') {
$this->$add(
$props['html_type'],
$setting,
ts($props['title']),
- CRM_Utils_Array::value($props['html_type'] == 'select' ? 'option_values' : 'html_attributes', $props, array()),
- $props['html_type'] == 'select' ? CRM_Utils_Array::value('html_attributes', $props) : NULL
+ ($options !== NULL) ? $options['values'] : CRM_Utils_Array::value('html_attributes', $props, array()),
+ ($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, array()) : NULL
);
}
elseif ($add == 'addSelect') {
- $options = civicrm_api3('Setting', 'getoptions', array(
- 'field' => $setting,
- ));
$this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
}
+ elseif ($add == 'addChainSelect') {
+ $this->addChainSelect($setting, array(
+ 'label' => ts($props['title']),
+ ));
+ }
else {
$this->$add($setting, ts($props['title']));
}
* This class generates form components for Localization.
*/
class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting {
- // use this variable to store mappings that we compute in buildForm and also
- // use in postProcess (CRM-1496)
- protected $_currencySymbols;
+
+ protected $_settings = array(
+ 'countryLimit' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'customTranslateFunction' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'defaultContactCountry' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'defaultContactStateProvince' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'defaultCurrency' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'fieldSeparator' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'inheritLocale' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'lcMessages' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'legacyEncoding' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'monetaryThousandSeparator' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'monetaryDecimalPoint' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'moneyformat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'moneyvalueformat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ 'provinceLimit' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
+ );
/**
* Build the form object.
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
- $i18n = CRM_Core_I18n::singleton();
CRM_Utils_System::setTitle(ts('Settings - Localization'));
- $locales = CRM_Core_I18n::languages();
$warningTitle = json_encode(ts("Warning"));
+ $lcMessages = CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions();
+
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
- if ($domain->locales) {
- // for multi-lingual sites, populate default language drop-down with available languages
- $lcMessages = array();
- foreach ($locales as $loc => $lang) {
- if (substr_count($domain->locales, $loc)) {
- $lcMessages[$loc] = $lang;
- }
- }
- $this->addElement('select', 'lcMessages', ts('Default Language'), $lcMessages);
+ if ($domain->locales) {
// add language limiter and language adder
$this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($lcMessages), NULL, NULL, NULL, NULL, ' ');
- $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff($locales, $lcMessages)));
+ $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff(CRM_Core_I18n::languages(), $lcMessages)));
// add the ability to return to single language
$warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
);
}
else {
- // for single-lingual sites, populate default language drop-down with all languages
- $this->addElement('select', 'lcMessages', ts('Default Language'), $locales);
-
$warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
$this->assign('warning', $warning);
$warning = json_encode($warning);
'undefined' => ts('Leave undefined'),
'current_site_language' => ts('Use language in use at the time'),
));
- $this->addElement('checkbox', 'inheritLocale', ts('Inherit CMS Language'));
- $this->addElement('text', 'monetaryThousandSeparator', ts('Thousands Separator'), array('size' => 2));
- $this->addElement('text', 'monetaryDecimalPoint', ts('Decimal Delimiter'), array('size' => 2));
- $this->addElement('text', 'moneyformat', ts('Monetary Amount Display'));
- $this->addElement('text', 'moneyvalueformat', ts('Monetary Value Display'));
-
- $country = array();
- CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
- $i18n->localizeArray($country, array('context' => 'country'));
- asort($country);
-
- $includeCountry = &$this->addElement('advmultiselect', 'countryLimit',
- ts('Available Countries') . ' ', $country,
- array(
- 'size' => 5,
- 'style' => 'width:150px',
- 'class' => 'advmultiselect',
- )
- );
-
- $includeCountry->setButtonAttributes('add', array('value' => ts('Add >>')));
- $includeCountry->setButtonAttributes('remove', array('value' => ts('<< Remove')));
-
- $includeState = &$this->addElement('advmultiselect', 'provinceLimit',
- ts('Available States and Provinces') . ' ', $country,
- array(
- 'size' => 5,
- 'style' => 'width:150px',
- 'class' => 'advmultiselect',
- )
- );
-
- $includeState->setButtonAttributes('add', array('value' => ts('Add >>')));
- $includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
-
- $this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
- $this->addChainSelect('defaultContactStateProvince', array('label' => ts('Default State/Province')));
-
- // we do this only to initialize currencySymbols, kinda hackish but works!
- $config->defaultCurrencySymbol();
-
- $symbol = $config->currencySymbols;
- foreach ($symbol as $key => $value) {
- $this->_currencySymbols[$key] = "$key";
- if ($value) {
- $this->_currencySymbols[$key] .= " ($value)";
- }
- }
- $this->addElement('select', 'defaultCurrency', ts('Default Currency'), $this->_currencySymbols);
$includeCurrency = &$this->addElement('advmultiselect', 'currencyLimit',
- ts('Available Currencies') . ' ', $this->_currencySymbols,
+ ts('Available Currencies') . ' ', self::getCurrencySymbols(),
array(
'size' => 5,
'style' => 'width:150px',
$includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
$includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
- $this->addElement('text', 'legacyEncoding', ts('Legacy Encoding'));
- $this->addElement('text', 'customTranslateFunction', ts('Custom Translate Function'));
- $this->addElement('text', 'fieldSeparator', ts('Import / Export Field Separator'), array('size' => 2));
-
$this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
parent::buildQuickForm();
public function postProcess() {
$values = $this->exportValues();
- // FIXME: stupid QF not submitting unchecked checkboxen…
- if (!isset($values['inheritLocale'])) {
- $values['inheritLocale'] = 0;
- }
-
//cache contact fields retaining localized titles
//though we changed localization, so reseting cache.
CRM_Core_BAO_Cache::deleteGroup('contact fields');
// we do this only to initialize monetary decimal point and thousand separator
$config = CRM_Core_Config::singleton();
- // set default Currency Symbol
- $values['defaultCurrencySymbol'] = $config->defaultCurrencySymbol($values['defaultCurrency']);
-
// save enabled currencies and defaul currency in option group 'currencies_enabled'
// CRM-1496
if (empty($values['currencyLimit'])) {
// get labels for all the currencies
$options = array();
+ $currencySymbols = self::getCurrencySymbols();
for ($i = 0; $i < count($values['currencyLimit']); $i++) {
$options[] = array(
- 'label' => $this->_currencySymbols[$values['currencyLimit'][$i]],
+ 'label' => $currencySymbols[$values['currencyLimit'][$i]],
'value' => $values['currencyLimit'][$i],
'weight' => $i + 1,
'is_active' => 1,
}
}
+ /**
+ * @return array
+ */
+ public static function getAvailableCountries() {
+ $i18n = CRM_Core_I18n::singleton();
+ $country = array();
+ CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
+ $i18n->localizeArray($country, array('context' => 'country'));
+ asort($country);
+ return $country;
+ }
+
+ /**
+ * @return array
+ */
+ public static function getDefaultLocaleOptions() {
+ $domain = new CRM_Core_DAO_Domain();
+ $domain->find(TRUE);
+ $locales = CRM_Core_I18n::languages();
+ if ($domain->locales) {
+ // for multi-lingual sites, populate default language drop-down with available languages
+ $lcMessages = array();
+ foreach ($locales as $loc => $lang) {
+ if (substr_count($domain->locales, $loc)) {
+ $lcMessages[$loc] = $lang;
+ }
+ }
+ }
+ else {
+ $lcMessages = $locales;
+ }
+ return $lcMessages;
+ }
+
+ /**
+ * Get a list of currencies (with their symbols).
+ *
+ * @return array
+ * Array('USD' => 'USD ($)').
+ */
+ public static function getCurrencySymbols() {
+ $symbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
+ 'labelColumn' => 'symbol',
+ 'orderColumn' => TRUE,
+ ));
+ $_currencySymbols = array();
+ foreach ($symbols as $key => $value) {
+ $_currencySymbols[$key] = "$key";
+ if ($value) {
+ $_currencySymbols[$key] .= " ($value)";
+ }
+ }
+ return $_currencySymbols;
+ }
+
}
$this->imageUploadURL = CRM_Core_Config_Defaults::getImageUploadUrl();
$this->geocodeMethod = CRM_Utils_Geocode::getProviderClass();
+ $this->defaultCurrencySymbol = CRM_Core_Config_Defaults::getDefaultCurrencySymbol();
}
/**
return $url;
}
+ public static function getDefaultCurrencySymbol() {
+ $config = CRM_Core_Config::singleton();
+ return $config->defaultCurrencySymbol(Civi::settings()->get('defaultCurrency'));
+ }
+
}
public function defaultCurrencySymbol($defaultCurrency = NULL) {
static $cachedSymbol = NULL;
if (!$cachedSymbol || $defaultCurrency) {
- if ($this->defaultCurrency || $defaultCurrency) {
- $this->currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
+ $currency = $defaultCurrency ? $defaultCurrency : $this->defaultCurrency;
+ if ($currency) {
+ $currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
'labelColumn' => 'symbol',
'orderColumn' => TRUE,
));
- $currency = $defaultCurrency ? $defaultCurrency : $this->defaultCurrency;
- $cachedSymbol = CRM_Utils_Array::value($currency, $this->currencySymbols, '');
+ $cachedSymbol = CRM_Utils_Array::value($currency, $currencySymbols, '');
}
else {
$cachedSymbol = '$';
*/
return array(
+ 'customTranslateFunction' => array(
+ 'add' => '4.7',
+ 'prefetch' => 1,
+ 'help_text' => NULL,
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'group_name' => 'Localization Preferences',
+ 'group' => 'localization',
+ 'name' => 'customTranslateFunction',
+ 'type' => 'String',
+ 'quick_form_type' => 'Element',
+ 'html_type' => 'text',
+ 'html_attributes' => array(
+ 'size' => '30',
+ 'maxlength' => '100',
+ ),
+ 'default' => NULL,
+ 'title' => 'Custom Translate Function',
+ 'description' => '',
+ ),
'monetaryThousandSeparator' => array(
'group_name' => 'Localization Preferences',
'group' => 'localization',
'name' => 'monetaryThousandSeparator',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'name' => 'monetaryDecimalPoint',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'name' => 'moneyformat',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'name' => 'moneyvalueformat',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
'quick_form_type' => 'Element',
'html_type' => 'text',
'default' => '%!i',
'add' => '4.3',
- 'title' => 'Monetary Amount Display',
+ 'title' => 'Monetary Value Display',
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
'name' => 'defaultCurrency',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
- 'quick_form_type' => 'Element',
- 'html_type' => 'text',
+ 'quick_form_type' => 'Select',
+ 'html_type' => 'Select',
'html_attributes' => array(
- 'size' => 2,
+ 'class' => 'crm-select2',
),
'default' => 'USD',
'add' => '4.3',
'is_contact' => 0,
'description' => 'Default currency assigned to contributions and other monetary transactions.',
'help_text' => NULL,
+ 'pseudoconstant' => array(
+ 'callback' => 'CRM_Admin_Form_Setting_Localization::getCurrencySymbols',
+ ),
),
'defaultContactCountry' => array(
'group_name' => 'Localization Preferences',
'name' => 'defaultContactCountry',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
- 'quick_form_type' => 'Element',
- 'html_type' => 'text',
+ 'quick_form_type' => 'Select',
+ 'html_type' => 'Select',
'html_attributes' => array(
- 'size' => 4,
+ //'class' => 'crm-select2',
),
'default' => '1228',
'add' => '4.4',
'is_contact' => 0,
'description' => 'This value is selected by default when adding a new contact address.',
'help_text' => NULL,
+ 'pseudoconstant' => array(
+ 'callback' => 'CRM_Admin_Form_Setting_Localization::getAvailableCountries',
+ ),
),
'defaultContactStateProvince' => array(
'add' => '4.7',
'prefetch' => 1,
- 'config_only' => 1,
'help_text' => NULL,
'is_domain' => 1,
'is_contact' => 0,
'group' => 'localization',
'name' => 'defaultContactStateProvince',
'type' => 'Integer',
- 'quick_form_type' => 'Select',
- 'html_type' => 'Select',
- 'pseudoconstant' => array(
- 'callback' => 'CRM_Core_PseudoConstant::stateProvince',
- ),
- 'default' => '',
+ 'quick_form_type' => 'ChainSelect',
+ 'html_type' => 'ChainSelect',
+ //'pseudoconstant' => array(
+ // 'callback' => 'CRM_Core_PseudoConstant::stateProvince',
+ //),
+ //'html_attributes',
+ 'default' => NULL,
'title' => 'Default State/Province',
'description' => 'This value is selected by default when adding a new contact address.',
),
'name' => 'countryLimit',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'Array',
- 'quick_form_type' => 'Element',
- 'html_type' => 'advmultiselect',
+ 'quick_form_type' => 'Select',
+ 'html_type' => 'Select',
'html_attributes' => array(
- 'size' => 5,
- 'style' => 'width:150px',
- 'class' => 'advmultiselect',
+ 'multiple' => 1,
+ 'class' => 'crm-select2',
),
'default' => 'null',
'add' => '4.3',
'is_contact' => 0,
'description' => '',
'help_text' => NULL,
+ 'pseudoconstant' => array(
+ 'callback' => 'CRM_Admin_Form_Setting_Localization::getAvailableCountries',
+ ),
),
'provinceLimit' => array(
'group_name' => 'Localization Preferences',
'name' => 'provinceLimit',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'Array',
- 'quick_form_type' => 'Element',
- 'html_type' => 'advmultiselect',
+ 'quick_form_type' => 'Select',
+ 'html_type' => 'Select',
'html_attributes' => array(
- 'size' => 5,
- 'style' => 'width:150px',
- 'class' => 'advmultiselect',
+ 'multiple' => 1,
+ 'class' => 'crm-select2',
),
'default' => 'null',
'add' => '4.3',
'is_contact' => 0,
'description' => '',
'help_text' => NULL,
+ 'pseudoconstant' => array(
+ 'callback' => 'CRM_Admin_Form_Setting_Localization::getAvailableCountries',
+ ),
),
'inheritLocale' => array(
'group_name' => 'Localization Preferences',
'name' => 'inheritLocale',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
- //@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'Boolean',
'quick_form_type' => 'YesNo',
'default' => '0',
'fieldSeparator' => array(
'add' => '4.7',
'prefetch' => 1,
- 'config_only' => 1,
'help_text' => NULL,
'is_domain' => 1,
'is_contact' => 0,
'name' => 'lcMessages',
'prefetch' => 1,
// prefetch causes it to be cached in config settings. Usually this is a transitional setting. Some things like urls are permanent. Remove this comment if you have assessed & it should be permanent
- 'config_only' => 1,
+ //'config_only' => 1,
//@todo - see https://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference#SettingsReference-Convertingaconfigobjecttoasetting on removing this deprecated value
'type' => 'String',
+ 'quick_form_type' => 'Select',
+ 'html_type' => 'Select',
+ 'html_attributes' => array(
+ 'class' => 'crm-select2',
+ ),
'default' => 'en_US',
'add' => '4.3',
'title' => 'Default Language',
'is_contact' => 0,
'description' => '',
'help_text' => NULL,
+ 'pseudoconstant' => array(
+ 'callback' => 'CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions',
+ ),
),
'legacyEncoding' => array(
'add' => '4.7',
'prefetch' => 1,
- 'config_only' => 1,
'help_text' => NULL,
'is_domain' => 1,
'is_contact' => 0,