-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-16395 Installation with localized default settings (more generic implementation) #8538
Changes from 9 commits
930ef8a
17cbdd5
2ed3bdd
b9e491e
b69560f
926e58e
5affa15
4a851ea
5ac92b2
fb42a73
2d6dbdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,40 +186,16 @@ public function postProcess() { | |
// we do this only to initialize monetary decimal point and thousand separator | ||
$config = CRM_Core_Config::singleton(); | ||
|
||
// save enabled currencies and defaul currency in option group 'currencies_enabled' | ||
// save enabled currencies and default currency in option group 'currencies_enabled' | ||
// CRM-1496 | ||
if (empty($values['currencyLimit'])) { | ||
$values['currencyLimit'] = array($values['defaultCurrency']); | ||
} | ||
elseif (!in_array($values['defaultCurrency'], | ||
$values['currencyLimit'] | ||
) | ||
) { | ||
elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) { | ||
$values['currencyLimit'][] = $values['defaultCurrency']; | ||
} | ||
|
||
// sort so that when we display drop down, weights have right value | ||
sort($values['currencyLimit']); | ||
|
||
// get labels for all the currencies | ||
$options = array(); | ||
|
||
$currencySymbols = self::getCurrencySymbols(); | ||
for ($i = 0; $i < count($values['currencyLimit']); $i++) { | ||
$options[] = array( | ||
'label' => $currencySymbols[$values['currencyLimit'][$i]], | ||
'value' => $values['currencyLimit'][$i], | ||
'weight' => $i + 1, | ||
'is_active' => 1, | ||
'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency'], | ||
); | ||
} | ||
|
||
$dontCare = NULL; | ||
CRM_Core_OptionGroup::createAssoc('currencies_enabled', | ||
$options, | ||
$dontCare | ||
); | ||
self::updateEnabledCurrencies($values['currencyLimit'], $values['defaultCurrency']); | ||
|
||
// unset currencyLimit so we dont store there | ||
unset($values['currencyLimit']); | ||
|
@@ -264,6 +240,38 @@ public function postProcess() { | |
} | ||
} | ||
|
||
|
||
/** | ||
* Replace available currencies by the ones provided | ||
* | ||
* @param $currencies array of currencies ['USD', 'CAD'] | ||
* @param $default default currency | ||
*/ | ||
public static function updateEnabledCurrencies($currencies, $default) { | ||
|
||
// sort so that when we display drop down, weights have right value | ||
sort($currencies); | ||
|
||
// get labels for all the currencies | ||
$options = array(); | ||
|
||
$currencySymbols = \CRM_Admin_Form_Setting_Localization::getCurrencySymbols(); | ||
for ($i = 0; $i < count($currencies); $i++) { | ||
$options[] = array( | ||
'label' => $currencySymbols[$currencies[$i]], | ||
'value' => $currencies[$i], | ||
'weight' => $i + 1, | ||
'is_active' => 1, | ||
'is_default' => $currencies[$i] == $default, | ||
); | ||
} | ||
|
||
$dontCare = NULL; | ||
\CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise |
||
|
||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
|
@@ -336,6 +344,44 @@ public static function onChangeLcMessages($oldLocale, $newLocale, $metadata, $do | |
} | ||
} | ||
|
||
public static function onChangeDefaultCurrency($oldCurrency, $newCurrency, $metadata) { | ||
if ($oldCurrency == $newCurrency) { | ||
return; | ||
} | ||
|
||
// ensure that default currency is always in the list of enabled currencies | ||
$currencies = array_keys(CRM_Core_OptionGroup::values('currencies_enabled')); | ||
if (!in_array($newCurrency, $currencies)) { | ||
if (empty($currencies)) { | ||
$currencies = array($values['defaultCurrency']); | ||
} | ||
else { | ||
$currencies[] = $newCurrency; | ||
} | ||
|
||
// sort so that when we display drop down, weights have right value | ||
sort($currencies); | ||
|
||
// get labels for all the currencies | ||
$options = array(); | ||
|
||
$currencySymbols = CRM_Admin_Form_Setting_Localization::getCurrencySymbols(); | ||
for ($i = 0; $i < count($currencies); $i++) { | ||
$options[] = array( | ||
'label' => $currencySymbols[$currencies[$i]], | ||
'value' => $currencies[$i], | ||
'weight' => $i + 1, | ||
'is_active' => 1, | ||
'is_default' => $currencies[$i] == $newCurrency, | ||
); | ||
} | ||
|
||
$dontCare = NULL; | ||
CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 4.7 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2015 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Core; | ||
|
||
use Civi; | ||
use Civi\Core\Event\SystemInstallEvent; | ||
|
||
/** | ||
* Class LocalizationInitializer | ||
* @package Civi\Core | ||
*/ | ||
class LocalizationInitializer { | ||
|
||
/** | ||
* Load the locale settings based on the installation language | ||
* | ||
* @param \Civi\Core\Event\SystemInstallEvent $event | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
public static function initialize(SystemInstallEvent $event) { | ||
|
||
// get the current installation language | ||
global $tsLocale; | ||
$seedLanguage = $tsLocale; | ||
if (!$seedLanguage) { | ||
return; | ||
} | ||
|
||
// get the corresponding settings file if any | ||
$localeDir = \CRM_Core_I18n::getResourceDir(); | ||
$fileName = $localeDir . $seedLanguage . DIRECTORY_SEPARATOR . 'settings.default.json'; | ||
|
||
// initalization | ||
$settingsParams = array(); | ||
|
||
if (file_exists($fileName)) { | ||
|
||
// load the file and parse it | ||
$json = file_get_contents($fileName); | ||
$settings = json_decode($json, TRUE); | ||
|
||
if (!empty($settings)) { | ||
// get all valid settings | ||
$results = civicrm_api3('Setting', 'getfields', array()); | ||
$validSettings = array_keys($results['values']); | ||
// add valid settings to params to send to api | ||
foreach ($settings as $setting => $value) { | ||
if (in_array($setting, $validSettings)) { | ||
$settingsParams[$setting] = $value; | ||
} | ||
|
||
} | ||
|
||
// ensure we don't mess with multilingual | ||
unset($settingsParams['languageLimit']); | ||
|
||
// support for enabled languages (option group) | ||
if (isset($settings['languagesOption']) && count($settings['languagesOption']) > 0) { | ||
\CRM_Core_BAO_OptionGroup::setActiveValues('languages', $settings['languagesOption']); | ||
} | ||
|
||
// set default currency in currencies_enabled (option group) | ||
if (isset($settings['defaultCurrency'])) { | ||
\CRM_Admin_Form_Setting_Localization::updateEnabledCurrencies(array($settings['defaultCurrency']), $settings['defaultCurrency']); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we're mapping
diff --git a/settings/Localization.setting.php b/settings/Localization.setting.php
index e375d92..3b7eac6 100644
--- a/settings/Localization.setting.php
+++ b/settings/Localization.setting.php
@@ -142,6 +142,9 @@ return array(
'defaultCurrency' => array(
'group_name' => 'Localization Preferences',
'group' => 'localization',
'name' => 'defaultCurrency',
'type' => 'String',
'quick_form_type' => 'Select',
'html_type' => 'Select',
'html_attributes' => array(
'class' => 'crm-select2',
),
'default' => 'USD',
'add' => '4.3',
'title' => 'Default Currency',
'is_domain' => 1,
'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',
),
+ 'on_change' => array(
+ 'CRM_Foo_Bar::onChangeDefaultCurrency',
+ ),
), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @totten I'm looking at your comments again and : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
} | ||
|
||
// in any case, enforce the seedLanguage as the default language | ||
$settingsParams['lcMessages'] = $seedLanguage; | ||
|
||
// apply the config | ||
civicrm_api3('Setting', 'create', $settingsParams); | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure the \ is needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, an unfortunate copy/paste