mirror of
https://github.com/getgrav/grav.git
synced 2026-02-04 22:00:13 +01:00
Persists to disk the plugin parameters currently stored in the Grav Config object
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user