From 85b56f1a13441dc3a84e638f4e665e77749c6794 Mon Sep 17 00:00:00 2001 From: Isabelle Date: Tue, 8 Sep 2026 18:05:59 +0200 Subject: [PATCH] fix(main): Separate slide tpl from banner tpl also added a toggle column for active in the group view --- config/routes.yml | 6 ++++++ src/Controller/CustomHtmlGroupController.php | 21 +++++++++++++++++++ .../CustomHtmlGroupGridDefinitionFactory.php | 10 +++++++-- views/templates/hook/_slide.tpl | 1 + views/templates/hook/_slider.tpl | 18 ++++++++-------- 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 views/templates/hook/_slide.tpl diff --git a/config/routes.yml b/config/routes.yml index b5595d4..665b9a1 100644 --- a/config/routes.yml +++ b/config/routes.yml @@ -39,6 +39,12 @@ customhtmlgroup_delete: defaults: _controller: 'Websmid\CustomHtml\Controller\CustomHtmlGroupController::deleteAction' +customhtmlgroup_toggle: + path: ws_customhtml/group/toggle/{idCustomHtmlGroup} + methods: [GET, POST] + defaults: + _controller: 'Websmid\CustomHtml\Controller\CustomHtmlGroupController::toggleAction' + customhtmlgroup_update_position: path: ws_customhtml/group/update-position methods: [POST] diff --git a/src/Controller/CustomHtmlGroupController.php b/src/Controller/CustomHtmlGroupController.php index 2bf3142..2b75ce0 100644 --- a/src/Controller/CustomHtmlGroupController.php +++ b/src/Controller/CustomHtmlGroupController.php @@ -106,6 +106,27 @@ class CustomHtmlGroupController extends FrameworkBundleAdminController return $this->redirectToRoute('customhtmlgroup_index'); } + public function toggleAction(int $idCustomHtmlGroup): RedirectResponse + { + $group = new CustomHtmlGroup($idCustomHtmlGroup); + + if (!Validate::isLoadedObject($group)) { + $this->addFlash('error', $this->trans('Unable to find the group.', 'Modules.Wscustomhtml.Admin')); + + return $this->redirectToRoute('customhtmlgroup_index'); + } + + $group->active = (int) !$group->active; + + if (!$group->update()) { + $this->addFlash('error', $this->trans('An error occurred while updating the status.', 'Admin.Notifications.Error')); + } else { + $this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success')); + } + + return $this->redirectToRoute('customhtmlgroup_index'); + } + public function updatePositionAction(Request $request): RedirectResponse { $positionDefinition = $this->get('websmid.customhtml.grid.position.customhtmlgroup_position_definition'); diff --git a/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php b/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php index 3a47da8..bb29fa6 100644 --- a/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php +++ b/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php @@ -9,6 +9,7 @@ use PrestaShop\PrestaShop\Core\Grid\Action\Type\SimpleGridAction; use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn; +use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ToggleColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\DeleteActionTrait; @@ -78,9 +79,14 @@ final class CustomHtmlGroupGridDefinitionFactory extends AbstractGridDefinitionF ->setOptions(['field' => 'blocks_count', 'sortable' => false]) ) ->add( - (new DataColumn('active')) + (new ToggleColumn('active')) ->setName($this->trans('Active', [], 'Admin.Global')) - ->setOptions(['field' => 'active']) + ->setOptions([ + 'field' => 'active', + 'primary_field' => 'id_ws_customhtml_group', + 'route' => 'customhtmlgroup_toggle', + 'route_param_name' => 'idCustomHtmlGroup', + ]) ) ->add( (new PositionColumn('position')) diff --git a/views/templates/hook/_slide.tpl b/views/templates/hook/_slide.tpl new file mode 100644 index 0000000..d09b418 --- /dev/null +++ b/views/templates/hook/_slide.tpl @@ -0,0 +1 @@ +{extends file="module:ws_customhtml/views/templates/hook/_banner.tpl"} diff --git a/views/templates/hook/_slider.tpl b/views/templates/hook/_slider.tpl index 50fbb53..4fc590d 100644 --- a/views/templates/hook/_slider.tpl +++ b/views/templates/hook/_slider.tpl @@ -7,11 +7,11 @@ {foreach from=$block.slides item="slide" name="slides"} {assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
- {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} + {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/slide.tpl"} {if file_exists($customhtmlOverridePath)} - {include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} + {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} + {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count} {/if}
{/foreach} @@ -26,11 +26,11 @@ {else}
{/if} - {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} + {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/slide.tpl"} {if file_exists($customhtmlOverridePath)} - {include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} + {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} + {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count} {/if}
{/foreach} @@ -44,11 +44,11 @@ {foreach from=$block.slides item="slide" name="slides"} {assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
- {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} + {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/slide.tpl"} {if file_exists($customhtmlOverridePath)} - {include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} + {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} + {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count} {/if}
{/foreach}