[ROUTE][ADMIN][CONFIG] Add route to update values in the config table
This commit is contained in:
parent
e286f39551
commit
44eaf43ba9
|
@ -30,9 +30,11 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
// use App\Core\GSEvent as Event;
|
// use App\Core\Event;
|
||||||
// use App\Util\Common;
|
// use App\Util\Common;
|
||||||
|
use App\Core\DB\DB;
|
||||||
use App\Core\DB\DefaultSettings;
|
use App\Core\DB\DefaultSettings;
|
||||||
|
use App\Core\Form;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
@ -44,28 +46,40 @@ class AdminConfigController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$options = [];
|
$defaults = DefaultSettings::$defaults;
|
||||||
foreach (DefaultSettings::$defaults as $key => $inner) {
|
$options = [];
|
||||||
|
foreach ($defaults as $key => $inner) {
|
||||||
$options[$key] = [];
|
$options[$key] = [];
|
||||||
foreach (array_keys($inner) as $inner_key) {
|
foreach (array_keys($inner) as $inner_key) {
|
||||||
$options[_m($key)][_m($inner_key)] = "{$key}:{$inner_key}";
|
$options[_m($key)][_m($inner_key)] = "{$key}:{$inner_key}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createFormBuilder(null, ['translation_domain' => false])
|
$form = Form::create([[_m('Setting'), ChoiceType::class, ['choices' => $options]],
|
||||||
->add(_m('Setting'), ChoiceType::class, ['choices' => $options])
|
[_m('Value'), TextType::class],
|
||||||
->add(_m('Value'), TextType::class)
|
['save', SubmitType::class, ['label' => _m('Set site setting')]], ]);
|
||||||
->add('save', SubmitType::class, ['label' => _m('Set site setting')])
|
|
||||||
->getForm();
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted()) {
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
if ($form->isValid() && array_key_exists(_m('Setting'), $data)) {
|
||||||
var_dump($data);
|
list($section, $setting) = explode(':', $data[_m('Setting')]);
|
||||||
|
$value = $data[_m('Value')];
|
||||||
// Stay in this page
|
$default = $defaults[$section][$setting];
|
||||||
return $this->redirect($request->getUri());
|
if (gettype($default) === gettype($value)) {
|
||||||
|
$conf = DB::find('\App\Entity\Config', ['section' => $section, 'setting' => $setting]);
|
||||||
|
$old_value = $conf->getValue();
|
||||||
|
$conf->setValue(serialize($value));
|
||||||
|
DB::flush();
|
||||||
|
}
|
||||||
|
return $this->render('config/admin.html.twig', [
|
||||||
|
'form' => $form->createView(),
|
||||||
|
'old_value' => unserialize($old_value),
|
||||||
|
'default' => $default,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Display error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('config/admin.html.twig', [
|
return $this->render('config/admin.html.twig', [
|
||||||
|
|
|
@ -16,5 +16,10 @@
|
||||||
{% block javascripts %}{% endblock %}
|
{% block javascripts %}{% endblock %}
|
||||||
|
|
||||||
{{ form(form) }}
|
{{ form(form) }}
|
||||||
|
|
||||||
|
{% if old_value is defined and default is defined %}
|
||||||
|
Old value: {{ old_value }} <br>
|
||||||
|
Default value: {{ default }}
|
||||||
|
{% endif %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user