Configuration: fill up the data from system configuration if user config doesn't exist

This commit is contained in:
Matias Griese
2014-10-06 14:38:14 +03:00
parent 9d1da6ccf3
commit 41821c57ab
7 changed files with 22 additions and 12 deletions

View File

@@ -222,10 +222,11 @@ class Admin
case 'configuration': case 'configuration':
case 'system': case 'system':
$type = 'system'; $type = 'system';
$blueprints = $this->blueprints($type); $blueprints = $this->blueprints("config/{$type}");
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml"); $config = $this->grav['config'];
$obj = new Data\Data($file->content(), $blueprints); $obj = new Data\Data($config->get('system'), $blueprints);
$obj->merge($post); $obj->merge($post);
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml");
$obj->file($file); $obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
break; break;
@@ -233,10 +234,11 @@ class Admin
case 'settings': case 'settings':
case 'site': case 'site':
$type = 'site'; $type = 'site';
$blueprints = $this->blueprints($type); $blueprints = $this->blueprints("config/{$type}");
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml"); $config = $this->grav['config'];
$obj = new Data\Data($file->content(), $blueprints); $obj = new Data\Data($config->get('site'), $blueprints);
$obj->merge($post); $obj->merge($post);
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml");
$obj->file($file); $obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
break; break;

View File

@@ -15,6 +15,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% include 'partials/blueprints.html.twig' with { blueprints: admin.blueprints('config/system'), data: admin.data('system') } %} {% set data = admin.data('system') %}
{% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %}
{% endblock %} {% endblock %}

View File

@@ -11,7 +11,7 @@
{% for field in field.fields %} {% for field in field.fields %}
{% if field.type %} {% if field.type %}
{% set value = data.value(field.name) %} {% set value = data.value(field.name) %}
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %} {% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>

View File

@@ -1,4 +1,6 @@
<form id="blueprints" method="post"> {% set form_id = form_id ? form_id : 'blueprints' %}
<form id="{{ form_id }}" method="post">
<h1>New Page</h1> <h1>New Page</h1>
{% for field in blueprints.fields %} {% for field in blueprints.fields %}
{% if field.type %} {% if field.type %}

View File

@@ -1,4 +1,6 @@
<form id="blueprints" method="post"> {% set form_id = form_id ? form_id : 'blueprints' %}
<form id="{{ form_id }}" method="post">
{% for field in blueprints.fields %} {% for field in blueprints.fields %}
{% if field.type %} {% if field.type %}
{% set value = data.value(field.name) %} {% set value = data.value(field.name) %}

View File

@@ -1,4 +1,6 @@
<form id="blueprints" method="post"> {% set form_id = form_id ? form_id : 'blueprints' %}
<form id="{{ form_id }}" method="post">
{% for field in blueprints.fields %} {% for field in blueprints.fields %}
{% if field.type %} {% if field.type %}
{% set value = data.value(field.name) %} {% set value = data.value(field.name) %}

View File

@@ -20,6 +20,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% include 'partials/blueprints.html.twig' with { blueprints: admin.blueprints('config/site'), data: admin.data('site') } %} {% set data = admin.data('site') %}
{% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %}
{% endblock %} {% endblock %}