mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 11:55:52 +01:00
Improve support for user defined blueprints in Configuration
This commit is contained in:
18
admin.php
18
admin.php
@@ -531,15 +531,6 @@ class AdminPlugin extends Plugin
|
|||||||
throw new \RuntimeException('One of the required plugins is missing or not enabled');
|
throw new \RuntimeException('One of the required plugins is missing or not enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Double check we have system.yaml and site.yaml
|
|
||||||
$config_files[] = $this->grav['locator']->findResource('user://config') . '/system.yaml';
|
|
||||||
$config_files[] = $this->grav['locator']->findResource('user://config') . '/site.yaml';
|
|
||||||
foreach ($config_files as $config_file) {
|
|
||||||
if (!file_exists($config_file)) {
|
|
||||||
touch($config_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize Admin Language if needed
|
// Initialize Admin Language if needed
|
||||||
/** @var Language $language */
|
/** @var Language $language */
|
||||||
$language = $this->grav['language'];
|
$language = $this->grav['language'];
|
||||||
@@ -566,6 +557,15 @@ class AdminPlugin extends Plugin
|
|||||||
// And store the class into DI container.
|
// And store the class into DI container.
|
||||||
$this->grav['admin'] = $this->admin;
|
$this->grav['admin'] = $this->admin;
|
||||||
|
|
||||||
|
// Double check we have system.yam, site.yaml etc
|
||||||
|
$config_path = $this->grav['locator']->findResource('user://config');
|
||||||
|
foreach ($this->admin->configurations() as $config_file) {
|
||||||
|
$config_file = "{$config_path}/{$config_file}.yaml";
|
||||||
|
if (!file_exists($config_file)) {
|
||||||
|
touch($config_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get theme for admin
|
// Get theme for admin
|
||||||
$this->theme = $this->config->get('plugins.admin.theme', 'grav');
|
$this->theme = $this->config->get('plugins.admin.theme', 'grav');
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Grav\Common\User\User;
|
|||||||
use Grav\Common\Utils;
|
use Grav\Common\Utils;
|
||||||
use RocketTheme\Toolbox\File\File;
|
use RocketTheme\Toolbox\File\File;
|
||||||
use RocketTheme\Toolbox\File\JsonFile;
|
use RocketTheme\Toolbox\File\JsonFile;
|
||||||
|
use RocketTheme\Toolbox\ResourceLocator\UniformResourceIterator;
|
||||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||||
use RocketTheme\Toolbox\Session\Message;
|
use RocketTheme\Toolbox\Session\Message;
|
||||||
use RocketTheme\Toolbox\Session\Session;
|
use RocketTheme\Toolbox\Session\Session;
|
||||||
@@ -334,9 +335,12 @@ class Admin
|
|||||||
$type = preg_replace('|config/|', '', $type);
|
$type = preg_replace('|config/|', '', $type);
|
||||||
$blueprints = $this->blueprints("config/{$type}");
|
$blueprints = $this->blueprints("config/{$type}");
|
||||||
$config = $this->grav['config'];
|
$config = $this->grav['config'];
|
||||||
$obj = new Data\Data($config->get($type), $blueprints);
|
$obj = new Data\Data($config->get($type, []), $blueprints);
|
||||||
$obj->merge($post);
|
$obj->merge($post);
|
||||||
$file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml"));
|
// FIXME: We shouldn't allow user to change configuration files in system folder!
|
||||||
|
$filename = $this->grav['locator']->findResource("config://{$type}.yaml")
|
||||||
|
?: $this->grav['locator']->findResource("config://{$type}.yaml", true, true);
|
||||||
|
$file = CompiledYamlFile::instance($filename);
|
||||||
$obj->file($file);
|
$obj->file($file);
|
||||||
$data[$type] = $obj;
|
$data[$type] = $obj;
|
||||||
} else {
|
} else {
|
||||||
@@ -689,18 +693,19 @@ class Admin
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the configuration files found
|
* Return the found configuration blueprints
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function configurations()
|
public static function configurations()
|
||||||
{
|
{
|
||||||
$configurations = [];
|
$configurations = [];
|
||||||
$path = Grav::instance()['locator']->findResource('user://config');
|
|
||||||
|
|
||||||
/** @var \DirectoryIterator $directory */
|
/** @var UniformResourceIterator $iterator */
|
||||||
foreach (new \DirectoryIterator($path) as $file) {
|
$iterator = Grav::instance()['locator']->getIterator('blueprints://config');
|
||||||
if ($file->isDir() || $file->isDot() || !preg_match('/^[^.].*.yaml$/', $file->getFilename())) {
|
|
||||||
|
foreach ($iterator as $file) {
|
||||||
|
if ($file->isDir() || !preg_match('/^[^.].*.yaml$/', $file->getFilename())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$configurations[] = basename($file->getBasename(), '.yaml');
|
$configurations[] = basename($file->getBasename(), '.yaml');
|
||||||
|
|||||||
Reference in New Issue
Block a user