I can see in the standard install profile how to add a single value into a config file.
// Enable the page cache and aggregation.
config_set('system.core', 'preprocess_css', '1');
config_set('system.core', 'preprocess_js', '1');
config_set('system.core', 'cache', '1');
But, where I need to add an array, I am having difficulty.
My specific use case, is that I'm trying to enable a filter in a text format.
So, I have something like this in filter.format.filtered_html.json
{
"filters": {
"filter_image_align": {
"status": 1,
"weight": 5,
"module": "filter",
"settings": []
},
"filter_html": {
"status": 1,
"weight": -10,
"settings": {
"allowed_html": "<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <p> <img> <figure> <figcaption>"
},
"module": "filter"
},
},
}
And I would like to add this filter:
"video_filter": {
"status": 1,
"weight": 0,
"module": "video_filter",
"settings": []
}
Is this even a legit way to enable a filter?
Can anyone help me with the syntax?
I agree with BWPanda about the better way to add a filter. As for your general question on how to add an array to a config file (which gets stored as json), have you tried:
$config = config('myconfig.settings'); $config->set('first_level.second_level', array('first_thing' => 'Primero', 'second_thing' => 'Segundo', 'third_thing' => 'Tercero')); $config->save();This results in:
{ "_config_name": "myconfig.settings", "first_level": { "second_level": { "first_thing": "Primero", "second_thing": "Segundo", "third_thing": "Tercero" } } }