From 87bc60a806a2624368fbb10c1b346ccef3f3b020 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 4 Jun 2020 20:37:17 +0000 Subject: [PATCH] [UI][CONFIG] Added admin configuration form --- src/Controller/AdminConfigController.php | 75 ++++++++++++++++++++++++ src/Routes/Main.php | 5 +- templates/base.html.twig | 8 ++- templates/config/admin.html.twig | 20 +++++++ 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 src/Controller/AdminConfigController.php create mode 100644 templates/config/admin.html.twig diff --git a/src/Controller/AdminConfigController.php b/src/Controller/AdminConfigController.php new file mode 100644 index 0000000000..09dbee461a --- /dev/null +++ b/src/Controller/AdminConfigController.php @@ -0,0 +1,75 @@ +. +// }}} + +/** + * Handle network public feed + * + * @package GNUsocial + * @category Controller + * + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Controller; + +// use App\Core\GSEvent as Event; +// use App\Util\Common; +use App\Core\DefaultSettings; +use App\Core\I18n; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\HttpFoundation\Request; + +class AdminConfigController extends AbstractController +{ + public function __invoke(Request $request) + { + $options = []; + foreach (DefaultSettings::$defaults as $key => $inner) { + $options[$key] = []; + foreach (array_keys($inner) as $inner_key) { + $options[I18n::_m($key)][I18n::_m($inner_key)] = "{$key}:{$inner_key}"; + } + } + + $form = $this->createFormBuilder() + ->add(I18n::_m('Setting'), ChoiceType::class, ['choices' => $options]) + ->add(I18n::_m('Value'), TextType::class) + ->add('save', SubmitType::class, ['label' => I18n::_m('Set site setting')]) + ->getForm(); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $data = $form->getData(); + + var_dump($data); + + // Stay in this page + return $this->redirect($request->getUri()); + } + + return $this->render('config/admin.html.twig', [ + 'form' => $form->createView(), + ]); + } +} diff --git a/src/Routes/Main.php b/src/Routes/Main.php index 77fcc5ea92..0e039770f9 100644 --- a/src/Routes/Main.php +++ b/src/Routes/Main.php @@ -30,13 +30,14 @@ namespace App\Routes; -use App\Controller\NetworkPublic; +use App\Controller as C; use App\Core\RouteLoader; abstract class Main { public static function load(RouteLoader $r): void { - $r->connect('main_all', '/main/all', NetworkPublic::class); + $r->connect('main_all', '/main/all', C\NetworkPublic::class); + $r->connect('config_admin', '/config/admin', C\AdminConfigController::class); } } diff --git a/templates/base.html.twig b/templates/base.html.twig index 043f42d1a4..6f4b11404b 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -2,8 +2,14 @@ - {% block title %}Welcome!{% endblock %} + {% block title %}Base page{% endblock %} {% block stylesheets %}{% endblock %} + {% block body %}{% endblock %} diff --git a/templates/config/admin.html.twig b/templates/config/admin.html.twig new file mode 100644 index 0000000000..4248c851ed --- /dev/null +++ b/templates/config/admin.html.twig @@ -0,0 +1,20 @@ + + + + + {% block title %}Admin Configuration page!{% endblock %} + {% block stylesheets %}{% endblock %} + + + + {% block body %}{% endblock %} + {% block javascripts %}{% endblock %} + + {{ form(form) }} + +