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.

General Questions /

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

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


Reply


4 Posts   1154 Views

Avatar
vwd

Community Member, 160 Posts

21 January 2013 at 9:03pm

Edited: 21/01/2013 9:05pm

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.

Avatar
Willr

Forum Moderator, 5513 Posts

24 January 2013 at 8:20pm

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.

Avatar
vwd

Community Member, 160 Posts

25 January 2013 at 1:04am

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

VWD.

Avatar
vwd

Community Member, 160 Posts

29 January 2013 at 9:31pm

Edited: 29/01/2013 9:31pm

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