I am currently trying to modify the configuration of my panel plugin via the panel.
The basic configuration is saved inside the config.php under site/config.
I tried using the Config::set method - but I found out that this functions only sets the “runtime config”. It does not save the config permanently.
Now I am a bit lost since I want that my plugin is able to save the config correctly as the user has done it.
In my case every Kirby project has multiple config files e.g.
config.localhost.php - for earlystage developing on my pc
config.testnet.php - for testing purposes and preview purposes for my customers
config.php - for shipping
If I use Config::get I will get the current “correct” configuration based on config.php and if applicable the config.<>.php.
I want to save the config in all files e.g. I have the following configuration array for my plugin:
My target is either - get the source of a given config value (e.g. maxStaleDays is from localhost.php since it overwrites config.php) and save the new value there (because I changed it on the defined domian) or save it in all applicable configuration files since it is in both files.
Is there a best practice / standard way to do this or are there any functions that could support me? - or am I required to implement all this on my own because Kirby does not offer a configuration change on runtine? - I could not find the function that fills $data in the Silo class and in the docs I cant find a usecase like this
IMO, a plugin should not fiddle with the config files at all. Why are you trying to store stuff in the config?
In general, /site/config.php is the default config, and site specific configs (localhost, staging, production etc.) should overwrite this file where needed.
What is the best practice if I want to save some plugin specific configurations that must be accessible for my customers (best case via the panel)?
My goal is to provide a base configuration (currently inside the config.php / with default values) but if they want to modify something I want them to do it via the panel since most of my clients are not able to use SFTP or SSH to modify the config directly…
Please be aware that my plugin should not modify any other configuration except the own “namespace”. In the current version I created a method that checks if the changed key is allowed and inside the nodework.embed-footer-control namespace… after that the whole file is overwritten (I am not happy with this solution either but I didnt find best practices for this usecase…
Another idea would be to create a new file inside the sites/config folder but then I cant use the normal config file like almost any other plugin…
If you have a better idea I would really appreciate your help
okay, if I understand this correctly - the proposed “best practice” like way is to “split” this configuration into “plugin conf” → like always in index.php and overriden by config.php
and a second file “nodework-settings.conf” for “user conf”.
I would wish to have all configuration in the same place but this is acceptable - but with _DIR_ the config file would life within the plugin folder this could be problematic for updates - is it “best practice” to save the nodework-settings.php inside the site/config folder (also for persistence if a user updates with drag and drop) - or is this not “the kirby way” - I would really like to match the standards as good as possible