From 8d048c689fbfba1691902fe41da385e2ba142e0f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 18 Dec 2015 14:44:03 +0100 Subject: [PATCH] Persists to disk the plugin parameters currently stored in the Grav Config object --- system/src/Grav/Common/Plugin.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/system/src/Grav/Common/Plugin.php b/system/src/Grav/Common/Plugin.php index 3f2f90aa1..b2084205f 100644 --- a/system/src/Grav/Common/Plugin.php +++ b/system/src/Grav/Common/Plugin.php @@ -6,6 +6,7 @@ use Grav\Common\Page\Page; use Grav\Common\Config\Config; use RocketTheme\Toolbox\Event\EventDispatcher; use RocketTheme\Toolbox\Event\EventSubscriberInterface; +use RocketTheme\Toolbox\File\YamlFile; /** * The Plugin object just holds the id and path to a plugin. @@ -182,4 +183,27 @@ class Plugin implements EventSubscriberInterface // Return configurations as a new data config class return new Data($header); } + + /** + * Persists to disk the plugin parameters currently stored in the Grav Config object + * + * @param string $plugin_name The name of the plugin whose config it should store. + * If omitted, saves the current plugin + * + * @return true + */ + protected function saveConfig($plugin_name = '') { + if (!$plugin_name) { + $plugin_name = $this->name; + } + + $locator = $this->grav['locator']; + $filename = 'config://plugins/' . $plugin_name . '.yaml'; + $file = YamlFile::instance($locator->findResource($filename, true, true)); + $content = $this->grav['config']->get('plugins.' . $plugin_name); + $file->save($content); + $file->free(); + + return true; + } }