Is it possible to change plugin config programmatically?

I’d like to implement a checkbox that the site admin can set in the plugin settings. And when he decides to store the settings I’d like to evaluate this checkbox and reset it afterwards. Is that possible?

Of course. The settings is in a YAML file and YAML files can be changed from a plugin. Just start with the Plugin Tutorial and hack your way through :wink:

Thanks for your reply. I already went through the tutorial and I tried it with the following code:

public function onAdminSave(Event $event)
    $config = (array) $this->config->get('');
    // shows the non-modified config: "icalendar_update" => "1" as expected

    $this->config->set('', '0');
    // modify and store a setting: 'saveConfig' returns 'true' as expected

    $config = (array) $this->config->get('');
    // shows the modified config: "icalendar_update" => "0" as expected

The above code seems to work as expected, but the line in the according file in user/config is still:

icalendar_update: '1'

So storing the setting doesn’t seem to work. What am I doing wrong?

Just a guess: is the code modifying the user/plugins/events/events.yaml file instead?

No, this file is also not being modified. I have no idea what ‘saveConfig’ does.

It persists the changed configuration to disk. Config also has a setter, so you can change it on run-time without changing files:

$this->grav['config']->set('config.key', 'value');

I do want to change the config file. But it doesn’t work. It always remains unchanged.