What is the best way (via code, e.g. in a custom module) to check if a configuration file already exists?
Accepted answer
Comments
@Herb suggests (on Zulip) something like this:
$config = config('mymodule.settings');
if (!$config->isNew()) {
If the config has never existed before then it'll exist only as an object and have the isNew flag. Otherwise you know it existed previously.
You could also use:
config_get_info()
(requires the Configuration Manager module to be enabled) and look for the name of your config file among the returned keys.- PHP's
file_exists()
function, along with the path to the config directory (maybe get it fromconfig_get_config_storage()
?)
There's probably lots of other ways too...
@Herb suggests (on Zulip) something like this: