fix(main): Separate slide tpl from banner tpl
also added a toggle column for active in the group view
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{extends file="module:ws_customhtml/views/templates/hook/_banner.tpl"}
|
||||
@@ -7,11 +7,11 @@
|
||||
{foreach from=$block.slides item="slide" name="slides"}
|
||||
{assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
|
||||
<div class="swiper-slide">
|
||||
{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}
|
||||
</div>
|
||||
{/foreach}
|
||||
@@ -26,11 +26,11 @@
|
||||
{else}
|
||||
<div class="customhtml-slider-grid-item col">
|
||||
{/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}
|
||||
</div>
|
||||
{/foreach}
|
||||
@@ -44,11 +44,11 @@
|
||||
{foreach from=$block.slides item="slide" name="slides"}
|
||||
{assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
|
||||
<div class="swiper-slide">
|
||||
{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}
|
||||
</div>
|
||||
{/foreach}
|
||||
|
||||
Reference in New Issue
Block a user