Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » New config system - setting a module's config values from mysite/_config.php instead of module/_config/module.yml

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 958 Views
  • vwd
    Avatar
    Community Member
    158 Posts

    New config system - setting a module's config values from mysite/_config.php instead of module/_config/module.yml Link to this post

    Hi,

    I'm trying to bring SS3 config code more in line with the new config system. How can I set configuration values of a module outside of the module's _config/*.yml?

    For example, a problem I'm trying to address is that I'm making changes to the silverstripe-googlesitemaps default configuration ie google_notification_enabled=true.

    googlesitemaps/_config/googlesitemaps.yml

    ---
    Name: googlesitemaps
    ---
    GoogleSitemap:
    enabled: true
    objects_per_sitemap: 1000
    google_notification_enabled: true
    use_show_in_search: true

    Everytime I run a composer update and a new version is downloaded, the settings that I've made are replaced with the module's default. Of course, I can merge them back after a source control diff but I'm wondering if there is a better way to do it.

    Previously, in /mysite/_config.php, I'd call GoogleSitemap::enable_google_notification(); which is now deprecated. But I could simply place the new equivalent in /mysite/_config.php:

    Config::inst()->update('GoogleSitemap', 'google_notification_enabled', true);

    Is this the best/only approach? Or is it better to stick with modifying the _config/googlesitemaps.yml to keep in line with the new Config approach and get the performance benefits. Or would the performance benefits be negligible ?

    Also from what I read in the documentation, the _config/ directory containing the YAML files seemed to be focused on modules. Another approach could be a mysite/_config/sitewide.yml where we can do site wide overrides of modules' default configuration variables? If so what would the syntax be to modify another module's configuration values?

    Thanks.

    Kind regards,
    VWD.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: New config system - setting a module's config values from mysite/_config.php instead of module/_config/module.yml Link to this post

    Take a look at the example YAML files in framework and cms. You'll want to use After to indicate that your configuration should be loaded *after* the modules default.

    http://doc.silverstripe.org/framework/en/topics/configuration has an in-depth explaination.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: New config system - setting a module's config values from mysite/_config.php instead of module/_config/module.yml Link to this post

    Thanks for your reply Will. Will give it a shot.

    VWD.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: New config system - setting a module's config values from mysite/_config.php instead of module/_config/module.yml Link to this post

    Here's what I did and it seems to work:

    mysite/_config/sitewide.yml

    ---
    Name: googlesitemapsoverride
    After:
    - '#googlesitemaps'
    ---
    GoogleSitemap:
    google_notification_enabled: true

    Hope it's useful to others too.

    Thanks Will.
    VWD

    958 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.