Show any configuration item Grav finds under user/config, if there is an associated blueprint provided

Also, organize current system/site/info files under a common
config.html.twig. Delete info/site/system twig files. Preserve BC by
setting the template of system/site/info to "config", in the pages.
This commit is contained in:
Flavio Copes
2016-01-03 17:53:04 +01:00
parent f34a9d7638
commit ae1b2a074c
10 changed files with 108 additions and 103 deletions

View File

@@ -335,6 +335,15 @@ class Admin
$obj = User::load(preg_replace('|users/|', '', $type));
$obj->merge($post);
$data[$type] = $obj;
} elseif (preg_match('|config/|', $type)) {
$type = preg_replace('|config/|', '', $type);
$blueprints = $this->blueprints("config/{$type}");
$config = $this->grav['config'];
$obj = new Data\Data($config->get($type), $blueprints);
$obj->merge($post);
$file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml"));
$obj->file($file);
$data[$type] = $obj;
} else {
throw new \RuntimeException("Data type '{$type}' doesn't exist!");
@@ -706,6 +715,29 @@ class Admin
return $languages;
}
/**
* Return the configuration files found
*
* @return array
*/
public static function configurations()
{
$configurations = [];
$path = $this->grav['locator']->findResource('user://config');
/** @var \DirectoryIterator $directory */
foreach (new \DirectoryIterator($path) as $file) {
if ($file->isDir() || $file->isDot() || $file->getBasename()[0] == '.') {
continue;
}
$configurations[] = basename($file->getBasename(), '.yaml');
}
return $configurations;
}
/**
* Return the languages available in the site
*

0
pages/admin/config.md Normal file
View File

View File

@@ -1,6 +1,6 @@
---
title: PHP Info
template: config
access:
admin.settings: true
admin.super: true

View File

@@ -1,6 +1,6 @@
---
title: Site Settings
template: config
access:
admin.settings: true
admin.super: true

View File

@@ -1,6 +1,6 @@
---
title: Configuration
template: config
access:
admin.configuration: true
admin.super: true

View File

@@ -0,0 +1,72 @@
{% extends 'partials/base.html.twig' %}
{% set config_slug = uri.basename %}
{% set isInfo = (config_slug == 'info') %}
{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ ("PLUGIN_ADMIN." ~ config_slug|upper)|tu %}
{% if not isInfo %}
{% set data = admin.data('config/' ~ config_slug) %}
{% endif %}
{% block stylesheets %}
{% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %}
{{ parent() }}
{% endblock %}
{% block javascripts %}
{% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %}
{% do assets.addJs(theme_url~'/js/mdeditor.js') %}
{{ parent() }}
{% endblock %}
{% block titlebar %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button>
</div>
<h1><i class="fa fa-fw fa-wrench"></i> {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ ("PLUGIN_ADMIN." ~ config_slug|upper)|tu }}</h1>
{% endblock %}
{% block content_top %}
<div class="alert notice">{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: <b>{{ data.file.filename|replace({(base_path):''}) }}</b></div>
<ul class="tab-bar">
<li {% if config_slug == 'system' %}class="active"{% endif %}>
{% if config_slug == 'system' %}<span>{% else %}<a href="{{ base_url_relative }}/config/system">{% endif %}
{{ "PLUGIN_ADMIN.SYSTEM"|tu }}
{% if config_slug == 'system' %}</span>{% else %}</a>{% endif %}
</li>
<li {% if config_slug == 'site' %}class="active"{% endif %}>
{% if config_slug == 'site' %}<span>{% else %}<a href="{{ base_url_relative }}/config/site">{% endif %}
{{ "PLUGIN_ADMIN.SITE"|tu }}
{% if config_slug == 'site' %}</span>{% else %}</a>{% endif %}
</li>
{% for configuration in admin.configurations %}
{% if configuration != 'system' and configuration != 'site' and admin.data('config/' ~ configuration).blueprints.fields is not empty %}
<li {% if config_slug == configuration %}class="active"{% endif %}>
{% if config_slug == configuration %}<span>{% else %}<a href="{{ base_url_relative }}/config/{{configuration}}">{% endif %}
{{ configuration|tu|capitalize }}
{% if config_slug == configuration %}</span>{% else %}</a>{% endif %}
</li>
{% endif %}
{% endfor %}
<li {% if config_slug == 'info' %}class="active"{% endif %}>
{% if config_slug == 'info' %}<span>{% else %}<a href="{{ base_url_relative }}/config/info">{% endif %}
{{ "PLUGIN_ADMIN.INFO"|tu }}
{% if config_slug == 'info' %}</span>{% else %}</a>{% endif %}
</li>
</ul>
{% endblock %}
{% block content %}
{% if isInfo %}
<div id="phpinfo">
{{ admin.phpinfo }}
</div>
{% else %}
{% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %}
{% endif %}
{% endblock %}

View File

@@ -1,23 +0,0 @@
{% extends 'partials/base.html.twig' %}
{% block titlebar %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
</div>
<h1><i class="fa fa-fw fa-wrench"></i> {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.PHP_INFO"|tu }}</h1>
{% endblock %}
{% block content_top %}
<ul class="tab-bar">
<li><a href="{{ base_url_relative }}/system">System</a></li>
<li><a href="{{ base_url_relative }}/site">Site</a></li>
<li class="active"><span>Info</span></li>
</ul>
{% endblock %}
{% block content %}
<div id="phpinfo">
{{ admin.phpinfo }}
</div>
{% endblock %}

View File

@@ -25,7 +25,7 @@
<a href="{{ base_url_relative }}"><i class="fa fa-fw fa-th"></i> {{ "PLUGIN_ADMIN.DASHBOARD"|tu }}</a>
</li>
{% if authorize(['admin.configuration', 'admin.super']) %}
<li class="{{ (location == 'system' or location == 'site') ? 'selected' : '' }}">
<li class="{{ (location == 'system' or location == 'site' or location == 'config') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/system"><i class="fa fa-fw fa-wrench"></i> {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }}</a>
</li>
{% endif %}

View File

@@ -1,38 +0,0 @@
{% extends 'partials/base.html.twig' %}
{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ "PLUGIN_ADMIN.SITE"|tu %}
{% set data = admin.data('site') %}
{% block stylesheets %}
{% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %}
{{ parent() }}
{% endblock %}
{% block javascripts %}
{% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %}
{% do assets.addJs(theme_url~'/js/mdeditor.js') %}
{{ parent() }}
{% endblock %}
{% block titlebar %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> Save</button>
</div>
<h1><i class="fa fa-fw fa-wrench"></i> {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.SITE"|tu }}</h1>
{% endblock %}
{% block content_top %}
<div class="alert notice">{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: <b>{{ data.file.filename|replace({(base_path):''}) }}</b></div>
<ul class="tab-bar">
<li><a href="{{ base_url_relative }}/system">{{ "PLUGIN_ADMIN.SYSTEM"|tu }}</a></li>
<li class="active"><span>{{ "PLUGIN_ADMIN.SITE"|tu }}</span></li>
<li><a href="{{ base_url_relative }}/info">{{ "PLUGIN_ADMIN.INFO"|tu }}</a></li>
</ul>
{% endblock %}
{% block content %}
{% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %}
{% endblock %}

View File

@@ -1,38 +0,0 @@
{% extends 'partials/base.html.twig' %}
{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ "PLUGIN_ADMIN.SYSTEM"|tu %}
{% set data = admin.data('system') %}
{% block stylesheets %}
{% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %}
{{ parent() }}
{% endblock %}
{% block javascripts %}
{% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %}
{% do assets.addJs(theme_url~'/js/mdeditor.js') %}
{{ parent() }}
{% endblock %}
{% block titlebar %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
<button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button>
</div>
<h1><i class="fa fa-fw fa-wrench"></i> {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.SYSTEM"|tu }}</h1>
{% endblock %}
{% block content_top %}
<div class="alert notice">{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: <b>{{ data.file.filename|replace({(base_path):''}) }}</b></div>
<ul class="tab-bar">
<li class="active"><span>{{ "PLUGIN_ADMIN.SYSTEM"|tu }}</span></li>
<li><a href="{{ base_url_relative }}/site">{{ "PLUGIN_ADMIN.SITE"|tu }}</a></li>
<li><a href="{{ base_url_relative }}/info">{{ "PLUGIN_ADMIN.INFO"|tu }}</a></li>
</ul>
{% endblock %}
{% block content %}
{% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %}
{% endblock %}