diff --git a/src/Controller/SystemConfigurationController.php b/src/Controller/SystemConfigurationController.php index 6379aeec..ffbaf1ab 100644 --- a/src/Controller/SystemConfigurationController.php +++ b/src/Controller/SystemConfigurationController.php @@ -29,6 +29,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TimezoneType; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; @@ -41,26 +42,21 @@ use Symfony\Component\Validator\Constraints\Regex; * @Route(path="/admin/system-config") * @Security("is_granted('system_configuration')") */ -class SystemConfigurationController extends AbstractController +final class SystemConfigurationController extends AbstractController { /** * @var EventDispatcherInterface */ - protected $eventDispatcher; + private $eventDispatcher; /** * @var SystemConfiguration */ - protected $configurations; + private $configurations; /** * @var ConfigurationRepository */ - protected $repository; + private $repository; - /** - * @param EventDispatcherInterface $dispatcher - * @param ConfigurationRepository $repository - * @param SystemConfiguration $config - */ public function __construct(EventDispatcherInterface $dispatcher, ConfigurationRepository $repository, SystemConfiguration $config) { $this->eventDispatcher = $dispatcher; @@ -70,10 +66,8 @@ class SystemConfigurationController extends AbstractController /** * @Route(path="/", name="system_configuration", methods={"GET"}) - * - * @return \Symfony\Component\HttpFoundation\Response */ - public function indexAction() + public function indexAction(): Response { $configSettings = $this->getInitializedConfigurations(); @@ -90,6 +84,30 @@ class SystemConfigurationController extends AbstractController ]); } + /** + * @Route(path="/edit/{section}", name="system_configuration_section", methods={"GET"}) + */ + public function sectionAction(string $section): Response + { + $configSettings = $this->getInitializedConfigurations(); + + $configurations = []; + foreach ($configSettings as $configModel) { + if ($configModel->getSection() !== $section) { + continue; + } + + $configurations[] = [ + 'model' => $configModel, + 'form' => $this->createConfigurationsForm($configModel)->createView(), + ]; + } + + return $this->render('system-configuration/index.html.twig', [ + 'sections' => $configurations, + ]); + } + /** * @Route(path="/update/{section}", name="system_configuration_update", methods={"POST"}) * diff --git a/templates/system-configuration/index.html.twig b/templates/system-configuration/index.html.twig index 6a395a16..fa39fa96 100644 --- a/templates/system-configuration/index.html.twig +++ b/templates/system-configuration/index.html.twig @@ -1,4 +1,4 @@ -{% extends 'base.html.twig' %} +{% extends app.request.xmlHttpRequest ? 'form.html.twig' : 'base.html.twig' %} {% import "system-configuration/actions.html.twig" as actions %} {% block page_title %}{{ 'title'|trans({}, 'system-configuration') }}{% endblock %} @@ -7,8 +7,10 @@ {% block main %} + {% set formEditTemplate = app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig' %} + {% for section in sections %} - {{ include('default/_form.html.twig', { + {{ include(formEditTemplate, { 'title': section.model.section|trans({}, 'system-configuration'), 'form': section.form, }) }} diff --git a/tests/Controller/SystemConfigurationControllerTest.php b/tests/Controller/SystemConfigurationControllerTest.php index 4d1f31f8..e95237c0 100644 --- a/tests/Controller/SystemConfigurationControllerTest.php +++ b/tests/Controller/SystemConfigurationControllerTest.php @@ -45,6 +45,25 @@ class SystemConfigurationControllerTest extends ControllerBaseTest } } + public function testSectionAction() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN); + $this->assertAccessIsGranted($client, '/admin/system-config/edit/timesheet'); + + $expectedForms = $this->getTestDataForms(); + + $result = $client->getCrawler()->filter('section.content div.box.box-primary'); + $this->assertEquals(1, count($result)); + + $result = $client->getCrawler()->filter('section.content div.box.box-primary form'); + $this->assertEquals(1, count($result)); + + $result = $client->getCrawler()->filter('form[name=system_configuration_form_timesheet]'); + $this->assertEquals(1, count($result)); + $form = $result->form(); + $this->assertEquals('POST', $form->getMethod()); + } + public function getTestDataForms() { return [