diff --git a/admin.php b/admin.php index 7e4540b6..1c4f9908 100644 --- a/admin.php +++ b/admin.php @@ -531,15 +531,6 @@ class AdminPlugin extends Plugin 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 /** @var Language $language */ $language = $this->grav['language']; @@ -566,6 +557,15 @@ class AdminPlugin extends Plugin // And store the class into DI container. $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 $this->theme = $this->config->get('plugins.admin.theme', 'grav'); diff --git a/classes/admin.php b/classes/admin.php index d3bf4128..26720225 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -15,6 +15,7 @@ use Grav\Common\User\User; use Grav\Common\Utils; use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\File\JsonFile; +use RocketTheme\Toolbox\ResourceLocator\UniformResourceIterator; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use RocketTheme\Toolbox\Session\Message; use RocketTheme\Toolbox\Session\Session; @@ -334,9 +335,12 @@ class Admin $type = preg_replace('|config/|', '', $type); $blueprints = $this->blueprints("config/{$type}"); $config = $this->grav['config']; - $obj = new Data\Data($config->get($type), $blueprints); + $obj = new Data\Data($config->get($type, []), $blueprints); $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); $data[$type] = $obj; } else { @@ -689,18 +693,19 @@ class Admin } /** - * Return the configuration files found + * Return the found configuration blueprints * * @return array */ public static function configurations() { $configurations = []; - $path = Grav::instance()['locator']->findResource('user://config'); - /** @var \DirectoryIterator $directory */ - foreach (new \DirectoryIterator($path) as $file) { - if ($file->isDir() || $file->isDot() || !preg_match('/^[^.].*.yaml$/', $file->getFilename())) { + /** @var UniformResourceIterator $iterator */ + $iterator = Grav::instance()['locator']->getIterator('blueprints://config'); + + foreach ($iterator as $file) { + if ($file->isDir() || !preg_match('/^[^.].*.yaml$/', $file->getFilename())) { continue; } $configurations[] = basename($file->getBasename(), '.yaml');