Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

3.1 Config API confusion


Reply


4 Posts   634 Views

Avatar
cwchong

Community Member, 13 Posts

5 November 2013 at 6:24pm

Hi, according to the changelog for 3.1.0, "Static properties are immutable and private, you must use Config API."

By this, I would think that we should have to change the following line in _config.php from:
i18n::set_locale('en_US');
to:
Config::inst()->update('i18n', 'current_locale', 'en_US');

But the doc page at http://doc.silverstripe.org/framework/en/topics/i18n still shows the code as
i18n::set_locale('en_US');

while further down the page, the datetime formats are updated using the new config::inst() method
Config::inst()->update('i18n', 'date_format', 'dd.MM.YYYY');

This seems quite arbitrary and confusing as to which config is still using the old or new method of updating.
Is there some inconsistency there or do I have to trial and error each configuration?

Avatar
Willr

Forum Moderator, 5513 Posts

6 November 2013 at 5:47pm

Hi cwchong, you are correct, at the moment it is quite confusing. The config API is still quite new and being rolled out in phases rather than one big change to replace everything.

Even more confusing is that that one method isn't updated yet the rest of the class appears updated. Pull requests to change this behaviour welcome. You'll need to patch the documentation (in the framework/docs folder) to ensure people update to the new syntax.

Avatar
cwchong

Community Member, 13 Posts

7 November 2013 at 6:33am

Hi Will, tks for the reply.

I am not that familiar with design of the Config class so would appreciate your advise here.
I have modified the frame\i18n\i18n.php file

private static $current_locale = ''; // changed visibility from protected to private
public static function set_locale($locale) { // changed to use Config class instead
Deprecation::notice('3.2', 'Use the "i18n.current_locale" config setting instead');
   if ($locale) Config::inst()->update('i18n', 'current_locale', $locale);
}


But that chunk essentially does nothing; using Config::inst()->update('i18n', 'current_locale', 'en_GB'); in the _config.php also does not seem to effect any change. What magic does the Config::inst()->update() do?

Avatar
Willr

Forum Moderator, 5513 Posts

7 November 2013 at 9:26pm

You'll need to update the getters to Config::inst()->get('i18n', 'current_locale'); rather than directly accessing property (easy if everything users getters). I believe that the private value on the class is only really there as a reference for available flags in the config system.

Calling update() does not change the private property and directly editing the private property also doesn't update the Config value from my tests.