[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;
|
||||
|
||||
// use App\Core\GSEvent as Event;
|
||||
// use App\Core\Event;
|
||||
// use App\Util\Common;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\DB\DefaultSettings;
|
||||
use App\Core\Form;
|
||||
use function App\Core\I18n\_m;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
@ -44,28 +46,40 @@ class AdminConfigController extends AbstractController
|
|||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$options = [];
|
||||
foreach (DefaultSettings::$defaults as $key => $inner) {
|
||||
$defaults = DefaultSettings::$defaults;
|
||||
$options = [];
|
||||
foreach ($defaults as $key => $inner) {
|
||||
$options[$key] = [];
|
||||
foreach (array_keys($inner) as $inner_key) {
|
||||
$options[_m($key)][_m($inner_key)] = "{$key}:{$inner_key}";
|
||||
}
|
||||
}
|
||||
|
||||
$form = $this->createFormBuilder(null, ['translation_domain' => false])
|
||||
->add(_m('Setting'), ChoiceType::class, ['choices' => $options])
|
||||
->add(_m('Value'), TextType::class)
|
||||
->add('save', SubmitType::class, ['label' => _m('Set site setting')])
|
||||
->getForm();
|
||||
$form = Form::create([[_m('Setting'), ChoiceType::class, ['choices' => $options]],
|
||||
[_m('Value'), TextType::class],
|
||||
['save', SubmitType::class, ['label' => _m('Set site setting')]], ]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
|
||||
var_dump($data);
|
||||
|
||||
// Stay in this page
|
||||
return $this->redirect($request->getUri());
|
||||
if ($form->isValid() && array_key_exists(_m('Setting'), $data)) {
|
||||
list($section, $setting) = explode(':', $data[_m('Setting')]);
|
||||
$value = $data[_m('Value')];
|
||||
$default = $defaults[$section][$setting];
|
||||
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', [
|
||||
|
|
|
@ -16,5 +16,10 @@
|
|||
{% block javascripts %}{% endblock %}
|
||||
|
||||
{{ form(form) }}
|
||||
|
||||
{% if old_value is defined and default is defined %}
|
||||
Old value: {{ old_value }} <br>
|
||||
Default value: {{ default }}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user