Jump to:

1132 Posts in 1966 Topics by 403 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » 3.1 Config API confusion

Ask questions about upgrading SilverStripe to the latest version.

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

Page: 1
Go to End
Author Topic: 347 Views
  • cwchong
    Avatar
    Community Member
    13 Posts

    3.1 Config API confusion Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: 3.1 Config API confusion Link to this post

    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.

  • cwchong
    Avatar
    Community Member
    13 Posts

    Re: 3.1 Config API confusion Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: 3.1 Config API confusion Link to this post

    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.

    347 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.