diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea8bf5..2f0be78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * feat(collection): add delete_attr, add_attr options * feat(builder): allow to add block between children * feat(builder): improve UI to add new block +* feat(settings): allow to edit a setting in plain page ## [v1.26.0] - 2025-03-17 ### Added diff --git a/src/core/Controller/Setting/NavigationSettingAdminController.php b/src/core/Controller/Setting/NavigationSettingAdminController.php index 4a3be8f..74bbb68 100644 --- a/src/core/Controller/Setting/NavigationSettingAdminController.php +++ b/src/core/Controller/Setting/NavigationSettingAdminController.php @@ -35,6 +35,8 @@ class NavigationSettingAdminController extends AdminController $session = $request->getSession(); $lastRequestId = sprintf('setting_request_%s_%s', get_class($entity), $entity->getId()); $lastRequest = $session->get($lastRequestId); + $options = $entity->getOptions(); + $optionView = $options['view'] ?? 'modal'; if (null !== $lastRequest && !$request->isMethod('POST')) { $fakeRequest = Request::create( @@ -64,17 +66,19 @@ class NavigationSettingAdminController extends AdminController $session->set($lastRequestId, $request->request->get('form')); $this->addFlash('warning', 'The form is not valid.'); - return $this->redirect(sprintf( - '%s?data-modal=%s', - $redirectTo, - urlencode($request->getUri()) - )); + if ($optionView === 'modal') { + return $this->redirect(sprintf( + '%s?data-modal=%s', + $redirectTo, + urlencode($request->getUri()) + )); + } } return $this->render('@Core/setting/navigation_setting_admin/edit.html.twig', [ 'form' => $form->createView(), 'entity' => $entity, - 'options' => $event->getData()['options'], + 'options' => $options, 'redirectTo' => $redirectTo, ]); } diff --git a/src/core/Controller/Setting/SettingAdminController.php b/src/core/Controller/Setting/SettingAdminController.php index 317fe77..707a19e 100644 --- a/src/core/Controller/Setting/SettingAdminController.php +++ b/src/core/Controller/Setting/SettingAdminController.php @@ -55,6 +55,8 @@ class SettingAdminController extends AdminController $session = $request->getSession(); $lastRequestId = sprintf('setting_request_%s_%s', get_class($entity), $entity->getId()); $lastRequest = $session->get($lastRequestId); + $options = $entity->getOptions(); + $optionView = $options['view'] ?? 'modal'; if (null !== $lastRequest && !$request->isMethod('POST')) { $fakeRequest = Request::create( @@ -82,11 +84,13 @@ class SettingAdminController extends AdminController $session->set($lastRequestId, $request->request->get('form')); $this->addFlash('warning', 'The form is not valid.'); - return $this->redirect(sprintf( - '%s?data-modal=%s', - $redirectTo, - urlencode($request->getUri()) - )); + if ($optionView === 'modal') { + return $this->redirect(sprintf( + '%s?data-modal=%s', + $redirectTo, + urlencode($request->getUri()) + )); + } } return $this->render('@Core/setting/setting_admin/edit.html.twig', [ diff --git a/src/core/Entity/NavigationSetting.php b/src/core/Entity/NavigationSetting.php index bfaa2ac..8adfb36 100644 --- a/src/core/Entity/NavigationSetting.php +++ b/src/core/Entity/NavigationSetting.php @@ -26,6 +26,9 @@ class NavigationSetting implements EntityInterface #[ORM\Column(type: 'text', nullable: true)] protected $value; + #[ORM\Column(type: 'text', nullable: true)] + protected $options; + #[ORM\ManyToOne(targetEntity: Navigation::class, inversedBy: 'navigationSettings')] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] protected $navigation; @@ -94,4 +97,16 @@ class NavigationSetting implements EntityInterface return $this; } + + public function getOptions() + { + return json_decode($this->options, true) ?? []; + } + + public function setOptions(?array $options): self + { + $this->options = json_encode($options ?? []); + + return $this; + } } diff --git a/src/core/Entity/Setting.php b/src/core/Entity/Setting.php index d4a1036..032e74a 100644 --- a/src/core/Entity/Setting.php +++ b/src/core/Entity/Setting.php @@ -25,6 +25,9 @@ class Setting implements EntityInterface #[ORM\Column(type: 'text', nullable: true)] protected $value; + #[ORM\Column(type: 'text', nullable: true)] + protected $options; + public function getId(): ?int { return $this->id; @@ -77,4 +80,16 @@ class Setting implements EntityInterface return $this; } + + public function getOptions() + { + return json_decode($this->options, true) ?? []; + } + + public function setOptions(?array $options): self + { + $this->options = json_encode($options ?? []); + + return $this; + } } diff --git a/src/core/Resources/views/admin/layout.html.twig b/src/core/Resources/views/admin/layout.html.twig index f6195ed..fd97838 100644 --- a/src/core/Resources/views/admin/layout.html.twig +++ b/src/core/Resources/views/admin/layout.html.twig @@ -1,4 +1,5 @@ {% apply spaceless %} +{% block html %} @@ -62,4 +63,5 @@ {% endblock %} +{% endblock %} {% endapply %} diff --git a/src/core/Resources/views/setting/navigation_setting_admin/edit.html.twig b/src/core/Resources/views/setting/navigation_setting_admin/edit.html.twig index 6e7c2a3..52a9aff 100644 --- a/src/core/Resources/views/setting/navigation_setting_admin/edit.html.twig +++ b/src/core/Resources/views/setting/navigation_setting_admin/edit.html.twig @@ -1,20 +1,77 @@ - +{% extends '@Core/admin/layout.html.twig' %} +{% set view = entity.options['view']|default('modal') %} + +{% block html %} + {% if view == 'modal' %} + + {% else %} + {{ parent() }} + {% endif %} +{% endblock %} + +{% block body_class %}has-form{% endblock %} + +{% block title %}{{ entity.label }}{% endblock %} + +{% block body %} + {% block header %} +
+
+ {% block header_title %} +

{{ entity.label }}

+ {% endblock %} + + {% block header_actions %} +
+
+ + + + {{ 'Back to the list'|trans }} + + + + +
+
+ {% endblock %} +
+
+ {% endblock %} + + {% block form %} +
+
+
+
+ {{ include('@Core/setting/navigation_setting_admin/_form.html.twig') }} +
+
+
+
+ {% endblock %} +{% endblock %} diff --git a/src/core/Resources/views/setting/setting_admin/edit.html.twig b/src/core/Resources/views/setting/setting_admin/edit.html.twig index 4bce97d..3836be1 100644 --- a/src/core/Resources/views/setting/setting_admin/edit.html.twig +++ b/src/core/Resources/views/setting/setting_admin/edit.html.twig @@ -1,20 +1,77 @@ - +{% extends '@Core/admin/layout.html.twig' %} +{% set view = entity.options['view']|default('modal') %} + +{% block html %} + {% if view == 'modal' %} + + {% else %} + {{ parent() }} + {% endif %} +{% endblock %} + +{% block body_class %}has-form{% endblock %} + +{% block title %}{{ entity.label }}{% endblock %} + +{% block body %} + {% block header %} +
+
+ {% block header_title %} +

{{ entity.label }}

+ {% endblock %} + + {% block header_actions %} +
+
+ + + + {{ 'Back to the list'|trans }} + + + + +
+
+ {% endblock %} +
+
+ {% endblock %} + + {% block form %} +
+
+
+
+ {{ include('@Core/setting/setting_admin/_form.html.twig') }} +
+
+
+
+ {% endblock %} +{% endblock %} diff --git a/src/core/Resources/views/setting/setting_admin/index.html.twig b/src/core/Resources/views/setting/setting_admin/index.html.twig index 7bf6c28..1ce4fe8 100644 --- a/src/core/Resources/views/setting/setting_admin/index.html.twig +++ b/src/core/Resources/views/setting/setting_admin/index.html.twig @@ -22,21 +22,35 @@ {% for item in pager %} + {% set view = item.options['view']|default('modal') %} {% set edit = path('admin_setting_edit', {entity: item.id, redirectTo: app.request.pathInfo}) %} - - {{ item.label|trans }} - + {% if view == 'modal' %} + + {{ item.label }} + + {% else %} + + {{ item.label }} + + {% endif %} {{ item.section|trans }} - - - + {% if view == 'modal' %} + + + + {% else %} + + + + {% endif %} + diff --git a/src/core/Resources/views/site/navigation_admin/_show.html.twig b/src/core/Resources/views/site/navigation_admin/_show.html.twig index f71b8df..54566de 100644 --- a/src/core/Resources/views/site/navigation_admin/_show.html.twig +++ b/src/core/Resources/views/site/navigation_admin/_show.html.twig @@ -54,21 +54,36 @@ {% for item in datas.settings %} + {% set view = item.options['view']|default('modal') %} + {% set edit = path('admin_navigation_setting_edit', {entity: item.id, redirectTo: app.request.pathInfo}) %} - - {{ item.label|trans }} - + {% if view == 'modal' %} + + {{ item.label }} + + {% else %} + + {{ item.label }} + + {% endif %} {{ item.section|trans }} - - - + {% if view == 'modal' %} + + + + {% else %} + + + + {% endif %} + diff --git a/src/core/Setting/NavigationSettingManager.php b/src/core/Setting/NavigationSettingManager.php index 91e038f..0d1a042 100644 --- a/src/core/Setting/NavigationSettingManager.php +++ b/src/core/Setting/NavigationSettingManager.php @@ -24,7 +24,14 @@ class NavigationSettingManager ) { } - public function init($navigation, string $code, string $section, string $label, $value = null) + public function init( + $navigation, + string $code, + string $section, + string $label, + $value = null, + array $options = [], + ) { $entity = $this->get($this->getNavigation($navigation), $code); $isNew = null === $entity; @@ -37,6 +44,7 @@ class NavigationSettingManager $entity ->setSection($section) ->setLabel($label) + ->setOptions($options) ; if ($isNew) { diff --git a/src/core/Setting/SettingManager.php b/src/core/Setting/SettingManager.php index da60fee..01e9f7e 100644 --- a/src/core/Setting/SettingManager.php +++ b/src/core/Setting/SettingManager.php @@ -21,7 +21,13 @@ class SettingManager ) { } - public function init(string $code, string $section, string $label, $value = null) + public function init( + string $code, + string $section, + string $label, + $value = null, + array $options = [], + ) { $entity = $this->get($code); $isNew = null === $entity; @@ -34,6 +40,7 @@ class SettingManager $entity ->setSection($section) ->setLabel($label) + ->setOptions($options) ; if ($isNew) {