Compare commits

..
4 Commits
Author SHA1 Message Date
isabelle 4e7333493a feat(main): Make FAQ and slide entities translatable 2026-09-09 13:17:58 +02:00
isabelle 7cafc376b7 feat(main): Made group and blocks translatable.
Still need to do slide and FAQ entities
2026-09-09 11:56:18 +02:00
isabelle 85b56f1a13 fix(main): Separate slide tpl from banner tpl
also added a toggle column for active in the group view
2026-09-08 18:05:59 +02:00
isabelle 620c34e353 feat(main: Added default block classes 2026-09-08 16:36:39 +02:00
48 changed files with 1118 additions and 268 deletions
+4 -7
View File
@@ -2,8 +2,7 @@ services:
websmid.customhtml.form.type.customhtml_group: websmid.customhtml.form.type.customhtml_group:
public: true public: true
class: 'Websmid\CustomHtml\Form\Type\CustomHtmlGroupType' class: 'Websmid\CustomHtml\Form\Type\CustomHtmlGroupType'
arguments: parent: "form.type.translatable.aware"
- '@translator'
tags: tags:
- { name: form.type } - { name: form.type }
@@ -37,24 +36,22 @@ services:
websmid.customhtml.form.type.customhtml_faq: websmid.customhtml.form.type.customhtml_faq:
public: true public: true
class: 'Websmid\CustomHtml\Form\Type\CustomHtmlFaqType' class: 'Websmid\CustomHtml\Form\Type\CustomHtmlFaqType'
arguments: parent: "form.type.translatable.aware"
- '@translator'
tags: tags:
- { name: form.type } - { name: form.type }
websmid.customhtml.form.type.customhtml_slide: websmid.customhtml.form.type.customhtml_slide:
public: true public: true
class: 'Websmid\CustomHtml\Form\Type\CustomHtmlSlideType' class: 'Websmid\CustomHtml\Form\Type\CustomHtmlSlideType'
arguments: parent: "form.type.translatable.aware"
- '@translator'
tags: tags:
- { name: form.type } - { name: form.type }
websmid.customhtml.form.type.customhtml_block: websmid.customhtml.form.type.customhtml_block:
public: true public: true
class: 'Websmid\CustomHtml\Form\Type\CustomHtmlBlockType' class: 'Websmid\CustomHtml\Form\Type\CustomHtmlBlockType'
parent: "form.type.translatable.aware"
arguments: arguments:
- '@translator'
- '@websmid.customhtml.form.choice_provider.customhtml_group_choice_provider' - '@websmid.customhtml.form.choice_provider.customhtml_group_choice_provider'
tags: tags:
- { name: form.type } - { name: form.type }
+6
View File
@@ -39,6 +39,12 @@ customhtmlgroup_delete:
defaults: defaults:
_controller: 'Websmid\CustomHtml\Controller\CustomHtmlGroupController::deleteAction' _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: customhtmlgroup_update_position:
path: ws_customhtml/group/update-position path: ws_customhtml/group/update-position
methods: [POST] methods: [POST]
+1 -3
View File
@@ -23,11 +23,9 @@ class Config
const SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET = 2; const SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET = 2;
const SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP = 3;
const SLIDER_MODES = [ const SLIDER_MODES = [
'always' => 'Always show as a slider', 'always' => 'Always show as a slider',
'responsive' => 'Slider on mobile/tablet, static grid on desktop', 'responsive' => 'Mobile only',
]; ];
const SLIDER_DEFAULT_MODE = 'always'; const SLIDER_DEFAULT_MODE = 'always';
+24 -10
View File
@@ -21,8 +21,11 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
{ {
public function indexAction(Request $request, CustomHtmlBlockFilters $filters): Response public function indexAction(Request $request, CustomHtmlBlockFilters $filters): Response
{ {
$idGroup = null;
if ($request->query->has('idGroup')) { if ($request->query->has('idGroup')) {
$filters->addFilter(['id_ws_customhtml_group' => (int) $request->query->get('idGroup')]); $idGroup = (int) $request->query->get('idGroup');
$filters->addFilter(['id_ws_customhtml_group' => $idGroup]);
$filters->setNeedsToBePersisted(false); $filters->setNeedsToBePersisted(false);
} }
@@ -31,7 +34,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
return $this->render('@Modules/ws_customhtml/views/templates/admin/grid/customhtmlblock.html.twig', [ return $this->render('@Modules/ws_customhtml/views/templates/admin/grid/customhtmlblock.html.twig', [
'customHtmlBlockGrid' => $this->presentGrid($grid), 'customHtmlBlockGrid' => $this->presentGrid($grid),
'layoutHeaderToolbarBtn' => $this->getToolbarButtons($request->get('_legacy_controller')), 'layoutHeaderToolbarBtn' => $this->getToolbarButtons($request->get('_legacy_controller'), $idGroup),
]); ]);
} }
@@ -51,9 +54,11 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
$formHandler = $this->get('websmid.customhtml.form.customhtmlblock_form_handler'); $formHandler = $this->get('websmid.customhtml.form.customhtmlblock_form_handler');
$form = $formBuilder->getForm(); $form = $formBuilder->getForm();
$idGroup = $request->query->has('idGroup') ? (int) $request->query->get('idGroup') : null;
$redirectParams = null !== $idGroup ? ['idGroup' => $idGroup] : [];
if ($request->isMethod('GET') && $request->query->has('idGroup')) { if ($request->isMethod('GET') && null !== $idGroup) {
$form->get('id_ws_customhtml_group')->setData((int) $request->query->get('idGroup')); $form->get('id_ws_customhtml_group')->setData($idGroup);
} }
$form->handleRequest($request); $form->handleRequest($request);
@@ -64,7 +69,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
if (null !== $handlerResult->getIdentifiableObjectId()) { if (null !== $handlerResult->getIdentifiableObjectId()) {
$this->addFlash('success', $this->trans('Successful creation.', 'Admin.Notifications.Success')); $this->addFlash('success', $this->trans('Successful creation.', 'Admin.Notifications.Success'));
return $this->redirectToRoute('customhtmlblock_index'); return $this->redirectToRoute('customhtmlblock_index', $redirectParams);
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->addFlash('error', $this->getErrorMessageForException($e, [])); $this->addFlash('error', $this->getErrorMessageForException($e, []));
@@ -72,6 +77,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
return $this->render('@Modules/ws_customhtml/views/templates/admin/form/customhtmlblock_create.html.twig', [ return $this->render('@Modules/ws_customhtml/views/templates/admin/form/customhtmlblock_create.html.twig', [
'customHtmlBlockForm' => $form->createView(), 'customHtmlBlockForm' => $form->createView(),
'idGroup' => $idGroup,
]); ]);
} }
@@ -81,6 +87,8 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
$formHandler = $this->get('websmid.customhtml.form.customhtmlblock_form_handler'); $formHandler = $this->get('websmid.customhtml.form.customhtmlblock_form_handler');
$form = $formBuilder->getFormFor($idCustomHtmlBlock); $form = $formBuilder->getFormFor($idCustomHtmlBlock);
$idGroup = $request->query->has('idGroup') ? (int) $request->query->get('idGroup') : null;
$redirectParams = null !== $idGroup ? ['idGroup' => $idGroup] : [];
try { try {
$form->handleRequest($request); $form->handleRequest($request);
@@ -89,7 +97,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
if ($handlerResult->isSubmitted() && $handlerResult->isValid()) { if ($handlerResult->isSubmitted() && $handlerResult->isValid()) {
$this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success')); $this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success'));
return $this->redirectToRoute('customhtmlblock_index'); return $this->redirectToRoute('customhtmlblock_index', $redirectParams);
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->addFlash('error', $this->getErrorMessageForException($e, [])); $this->addFlash('error', $this->getErrorMessageForException($e, []));
@@ -102,24 +110,28 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
'customHtmlBlockForm' => $form->createView(), 'customHtmlBlockForm' => $form->createView(),
'idCustomHtmlBlock' => $idCustomHtmlBlock, 'idCustomHtmlBlock' => $idCustomHtmlBlock,
'currentImageUrl' => $currentImageUrl, 'currentImageUrl' => $currentImageUrl,
'idGroup' => $idGroup,
]); ]);
} }
public function deleteAction(Request $request, int $idCustomHtmlBlock): RedirectResponse public function deleteAction(Request $request, int $idCustomHtmlBlock): RedirectResponse
{ {
$idGroup = $request->query->has('idGroup') ? (int) $request->query->get('idGroup') : null;
$redirectParams = null !== $idGroup ? ['idGroup' => $idGroup] : [];
$block = new CustomHtmlBlock($idCustomHtmlBlock); $block = new CustomHtmlBlock($idCustomHtmlBlock);
if (!Validate::isLoadedObject($block)) { if (!Validate::isLoadedObject($block)) {
$this->addFlash('error', $this->trans('Unable to find the block.', 'Modules.Wscustomhtml.Admin')); $this->addFlash('error', $this->trans('Unable to find the block.', 'Modules.Wscustomhtml.Admin'));
return $this->redirectToRoute('customhtmlblock_index'); return $this->redirectToRoute('customhtmlblock_index', $redirectParams);
} }
CustomHtmlFaq::deleteByBlockId($idCustomHtmlBlock); CustomHtmlFaq::deleteByBlockId($idCustomHtmlBlock);
$block->delete(); $block->delete();
$this->addFlash('success', $this->trans('Successful deletion.', 'Admin.Notifications.Success')); $this->addFlash('success', $this->trans('Successful deletion.', 'Admin.Notifications.Success'));
return $this->redirectToRoute('customhtmlblock_index'); return $this->redirectToRoute('customhtmlblock_index', $redirectParams);
} }
public function updatePositionAction(int $idGroup, Request $request): RedirectResponse public function updatePositionAction(int $idGroup, Request $request): RedirectResponse
@@ -144,7 +156,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
return $this->redirectToRoute('customhtmlblock_index', ['idGroup' => $idGroup]); return $this->redirectToRoute('customhtmlblock_index', ['idGroup' => $idGroup]);
} }
private function getToolbarButtons(?string $securitySubject): array private function getToolbarButtons(?string $securitySubject, ?int $idGroup = null): array
{ {
$toolbarButtons = []; $toolbarButtons = [];
@@ -152,8 +164,10 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController
return $toolbarButtons; return $toolbarButtons;
} }
$routeParams = null !== $idGroup ? ['idGroup' => $idGroup] : [];
$toolbarButtons['customhtmlblock_create'] = [ $toolbarButtons['customhtmlblock_create'] = [
'href' => $this->generateUrl('customhtmlblock_create'), 'href' => $this->generateUrl('customhtmlblock_create', $routeParams),
'desc' => $this->trans('New block', 'Admin.Actions'), 'desc' => $this->trans('New block', 'Admin.Actions'),
'icon' => 'add_circle_outline', 'icon' => 'add_circle_outline',
'class' => 'btn-primary', 'class' => 'btn-primary',
@@ -106,6 +106,27 @@ class CustomHtmlGroupController extends FrameworkBundleAdminController
return $this->redirectToRoute('customhtmlgroup_index'); 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 public function updatePositionAction(Request $request): RedirectResponse
{ {
$positionDefinition = $this->get('websmid.customhtml.grid.position.customhtmlgroup_position_definition'); $positionDefinition = $this->get('websmid.customhtml.grid.position.customhtmlgroup_position_definition');
@@ -5,6 +5,7 @@ namespace Websmid\CustomHtml\Form\ChoiceProvider;
use PrestaShop\PrestaShop\Core\Form\ConfigurableFormChoiceProviderInterface; use PrestaShop\PrestaShop\Core\Form\ConfigurableFormChoiceProviderInterface;
use PrestaShop\PrestaShop\Core\Form\FormChoiceAttributeProviderInterface; use PrestaShop\PrestaShop\Core\Form\FormChoiceAttributeProviderInterface;
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface; use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface;
use Context;
use Db; use Db;
final class CustomHtmlGroupChoiceProvider implements final class CustomHtmlGroupChoiceProvider implements
@@ -14,22 +15,9 @@ final class CustomHtmlGroupChoiceProvider implements
{ {
public function getChoices(array $options = []): array public function getChoices(array $options = []): array
{ {
$groups = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_group`, `title`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`
ORDER BY `title` ASC'
);
$titleCounts = array_count_values(array_column($groups, 'title'));
$choices = []; $choices = [];
foreach ($groups as $group) { foreach ($this->getGroupsWithLabels() as $label => $group) {
$label = $group['title'];
if ($titleCounts[$label] > 1) {
$label .= ' (#' . $group['id_ws_customhtml_group'] . ')';
}
$choices[$label] = (int) $group['id_ws_customhtml_group']; $choices[$label] = (int) $group['id_ws_customhtml_group'];
} }
@@ -38,6 +26,42 @@ final class CustomHtmlGroupChoiceProvider implements
public function getChoicesAttributes(): array public function getChoicesAttributes(): array
{ {
return []; $choicesAttributes = [];
foreach ($this->getGroupsWithLabels() as $label => $group) {
if (!empty($group['default_block_class'])) {
$choicesAttributes[$label]['data-default-block-class'] = $group['default_block_class'];
}
}
return $choicesAttributes;
}
private function getGroupsWithLabels(): array
{
$idLang = (int) Context::getContext()->language->id;
$groups = Db::getInstance()->executeS(
'SELECT g.`id_ws_customhtml_group`, gl.`title`, g.`default_block_class`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` g
LEFT JOIN `' . _DB_PREFIX_ . 'ws_customhtml_group_lang` gl
ON gl.`id_ws_customhtml_group` = g.`id_ws_customhtml_group` AND gl.`id_lang` = ' . $idLang . '
ORDER BY gl.`title` ASC'
);
$titleCounts = array_count_values(array_column($groups, 'title'));
$groupsWithLabels = [];
foreach ($groups as $group) {
$label = $group['title'];
if ($titleCounts[$label] > 1) {
$label .= ' (#' . $group['id_ws_customhtml_group'] . ')';
}
$groupsWithLabels[$label] = $group;
}
return $groupsWithLabels;
} }
} }
@@ -20,21 +20,21 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
$block = new CustomHtmlBlock(); $block = new CustomHtmlBlock();
$block->id_ws_customhtml_group = $idGroup; $block->id_ws_customhtml_group = $idGroup;
$block->title = (string) $formData['title']; $block->title = $formData['title'];
$block->type = (string) $formData['type']; $block->type = (string) $formData['type'];
$block->show_title = (int) $formData['show_title']; $block->show_title = (int) $formData['show_title'];
$block->custom_class = (string) ($formData['custom_class'] ?? ''); $block->custom_class = (string) ($formData['custom_class'] ?? '');
$block->content = (string) $formData['content']; $block->content = $formData['content'];
$block->description = (string) ($formData['description'] ?? ''); $block->description = $formData['description'] ?? [];
$block->extra_description = (string) ($formData['extra_description'] ?? ''); $block->extra_description = $formData['extra_description'] ?? [];
$block->link = (string) ($formData['link'] ?? ''); $block->link = $formData['link'] ?? [];
$block->link_text = (string) ($formData['link_text'] ?? ''); $block->link_text = $formData['link_text'] ?? [];
$block->alert_type = (string) ($formData['alert_type'] ?? 'info'); $block->alert_type = (string) ($formData['alert_type'] ?? 'info');
$block->timeout = (int) ($formData['timeout'] ?? 0); $block->timeout = (int) ($formData['timeout'] ?? 0);
$block->slider_mode = (string) ($formData['slider_mode'] ?? Config::SLIDER_DEFAULT_MODE); $block->slider_mode = (string) ($formData['slider_mode'] ?? Config::SLIDER_DEFAULT_MODE);
$block->slides_per_view_mobile = (float) ($formData['slides_per_view_mobile'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE); $block->slides_per_view_mobile = (float) ($formData['slides_per_view_mobile'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE);
$block->slides_per_view_tablet = (float) ($formData['slides_per_view_tablet'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET); $block->slides_per_view_tablet = (float) ($formData['slides_per_view_tablet'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET);
$block->slides_per_view_desktop = (float) ($formData['slides_per_view_desktop'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP); $block->slides_per_view_desktop = (float) ($formData['slides_per_view_desktop'] ?? 0);
$block->autoplay_delay = (int) ($formData['autoplay_delay'] ?? 0); $block->autoplay_delay = (int) ($formData['autoplay_delay'] ?? 0);
$block->image = $this->saveUploadedImage($formData['image'] ?? null, ''); $block->image = $this->saveUploadedImage($formData['image'] ?? null, '');
$block->active = (int) $formData['active']; $block->active = (int) $formData['active'];
@@ -59,21 +59,21 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
} }
$block->id_ws_customhtml_group = (int) $formData['id_ws_customhtml_group']; $block->id_ws_customhtml_group = (int) $formData['id_ws_customhtml_group'];
$block->title = (string) $formData['title']; $block->title = $formData['title'];
$block->type = (string) $formData['type']; $block->type = (string) $formData['type'];
$block->show_title = (int) $formData['show_title']; $block->show_title = (int) $formData['show_title'];
$block->custom_class = (string) ($formData['custom_class'] ?? ''); $block->custom_class = (string) ($formData['custom_class'] ?? '');
$block->content = (string) $formData['content']; $block->content = $formData['content'];
$block->description = (string) ($formData['description'] ?? ''); $block->description = $formData['description'] ?? [];
$block->extra_description = (string) ($formData['extra_description'] ?? ''); $block->extra_description = $formData['extra_description'] ?? [];
$block->link = (string) ($formData['link'] ?? ''); $block->link = $formData['link'] ?? [];
$block->link_text = (string) ($formData['link_text'] ?? ''); $block->link_text = $formData['link_text'] ?? [];
$block->alert_type = (string) ($formData['alert_type'] ?? 'info'); $block->alert_type = (string) ($formData['alert_type'] ?? 'info');
$block->timeout = (int) ($formData['timeout'] ?? 0); $block->timeout = (int) ($formData['timeout'] ?? 0);
$block->slider_mode = (string) ($formData['slider_mode'] ?? Config::SLIDER_DEFAULT_MODE); $block->slider_mode = (string) ($formData['slider_mode'] ?? Config::SLIDER_DEFAULT_MODE);
$block->slides_per_view_mobile = (float) ($formData['slides_per_view_mobile'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE); $block->slides_per_view_mobile = (float) ($formData['slides_per_view_mobile'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE);
$block->slides_per_view_tablet = (float) ($formData['slides_per_view_tablet'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET); $block->slides_per_view_tablet = (float) ($formData['slides_per_view_tablet'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET);
$block->slides_per_view_desktop = (float) ($formData['slides_per_view_desktop'] ?? Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP); $block->slides_per_view_desktop = (float) ($formData['slides_per_view_desktop'] ?? 0);
$block->autoplay_delay = (int) ($formData['autoplay_delay'] ?? 0); $block->autoplay_delay = (int) ($formData['autoplay_delay'] ?? 0);
$block->image = $this->saveUploadedImage($formData['image'] ?? null, $block->image); $block->image = $this->saveUploadedImage($formData['image'] ?? null, $block->image);
$block->active = (int) $formData['active']; $block->active = (int) $formData['active'];
@@ -146,14 +146,18 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
CustomHtmlFaq::deleteByBlockId($idBlock); CustomHtmlFaq::deleteByBlockId($idBlock);
foreach (array_values($faqs) as $position => $faqData) { foreach (array_values($faqs) as $position => $faqData) {
if (empty($faqData['question'])) { $question = $faqData['question'] ?? [];
if (empty(array_filter($question, static function ($value) {
return trim((string) $value) !== '';
}))) {
continue; continue;
} }
$faq = new CustomHtmlFaq(); $faq = new CustomHtmlFaq();
$faq->id_ws_customhtml = $idBlock; $faq->id_ws_customhtml = $idBlock;
$faq->question = (string) $faqData['question']; $faq->question = $question;
$faq->answer = (string) ($faqData['answer'] ?? ''); $faq->answer = $faqData['answer'] ?? [];
$faq->ordering = $position; $faq->ordering = $position;
$faq->add(); $faq->add();
} }
@@ -181,11 +185,11 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
$slide = new CustomHtmlSlide(); $slide = new CustomHtmlSlide();
$slide->id_ws_customhtml = $idBlock; $slide->id_ws_customhtml = $idBlock;
$slide->title = (string) ($slideData['title'] ?? ''); $slide->title = $slideData['title'] ?? [];
$slide->description = (string) ($slideData['description'] ?? ''); $slide->description = $slideData['description'] ?? [];
$slide->extra_description = (string) ($slideData['extra_description'] ?? ''); $slide->extra_description = $slideData['extra_description'] ?? [];
$slide->link = (string) ($slideData['link'] ?? ''); $slide->link = $slideData['link'] ?? [];
$slide->link_text = (string) ($slideData['link_text'] ?? ''); $slide->link_text = $slideData['link_text'] ?? [];
$slide->image = $this->saveUploadedImage($slideData['image'] ?? null, $existingImage); $slide->image = $this->saveUploadedImage($slideData['image'] ?? null, $existingImage);
$slide->ordering = $position; $slide->ordering = $position;
$slide->add(); $slide->add();
@@ -15,9 +15,10 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface
public function create(array $formData) public function create(array $formData)
{ {
$group = new CustomHtmlGroup(); $group = new CustomHtmlGroup();
$group->title = (string) $formData['title']; $group->title = $formData['title'];
$group->hook_name = (string) $formData['hook_name']; $group->hook_name = (string) $formData['hook_name'];
$group->custom_class = (string) ($formData['custom_class'] ?? ''); $group->custom_class = (string) ($formData['custom_class'] ?? '');
$group->default_block_class = (string) ($formData['default_block_class'] ?? '');
$group->active = (int) $formData['active']; $group->active = (int) $formData['active'];
$group->ordering = $this->getNextOrdering(); $group->ordering = $this->getNextOrdering();
@@ -47,9 +48,10 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface
return false; return false;
} }
$group->title = (string) $formData['title']; $group->title = $formData['title'];
$group->hook_name = (string) $formData['hook_name']; $group->hook_name = (string) $formData['hook_name'];
$group->custom_class = (string) ($formData['custom_class'] ?? ''); $group->custom_class = (string) ($formData['custom_class'] ?? '');
$group->default_block_class = (string) ($formData['default_block_class'] ?? '');
$group->active = (int) $formData['active']; $group->active = (int) $formData['active'];
if (!$group->update()) { if (!$group->update()) {
@@ -36,7 +36,7 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface
'slider_mode' => $block->slider_mode, 'slider_mode' => $block->slider_mode,
'slides_per_view_mobile' => (float) $block->slides_per_view_mobile, 'slides_per_view_mobile' => (float) $block->slides_per_view_mobile,
'slides_per_view_tablet' => (float) $block->slides_per_view_tablet, 'slides_per_view_tablet' => (float) $block->slides_per_view_tablet,
'slides_per_view_desktop' => (float) $block->slides_per_view_desktop, 'slides_per_view_desktop' => (float) $block->slides_per_view_desktop > 0 ? (float) $block->slides_per_view_desktop : null,
'autoplay_delay' => (int) $block->autoplay_delay, 'autoplay_delay' => (int) $block->autoplay_delay,
'faqs' => $this->loadFaqs((int) $id), 'faqs' => $this->loadFaqs((int) $id),
'slides' => $this->loadSlides((int) $id), 'slides' => $this->loadSlides((int) $id),
@@ -48,22 +48,22 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface
{ {
return [ return [
'id_ws_customhtml_group' => 0, 'id_ws_customhtml_group' => 0,
'title' => '', 'title' => [],
'type' => 'html', 'type' => 'html',
'show_title' => false, 'show_title' => false,
'custom_class' => '', 'custom_class' => '',
'content' => '', 'content' => [],
'image' => null, 'image' => null,
'description' => '', 'description' => [],
'extra_description' => '', 'extra_description' => [],
'link' => '', 'link' => [],
'link_text' => '', 'link_text' => [],
'alert_type' => 'info', 'alert_type' => 'info',
'timeout' => 0, 'timeout' => 0,
'slider_mode' => Config::SLIDER_DEFAULT_MODE, 'slider_mode' => Config::SLIDER_DEFAULT_MODE,
'slides_per_view_mobile' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE, 'slides_per_view_mobile' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_MOBILE,
'slides_per_view_tablet' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET, 'slides_per_view_tablet' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET,
'slides_per_view_desktop' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP, 'slides_per_view_desktop' => null,
'autoplay_delay' => 0, 'autoplay_delay' => 0,
'faqs' => [], 'faqs' => [],
'slides' => [], 'slides' => [],
@@ -17,20 +17,22 @@ final class CustomHtmlGroupDataProvider implements FormDataProviderInterface
} }
return [ return [
'title' => $group->title, 'title' => $group->title,
'hook_name' => $group->hook_name, 'hook_name' => $group->hook_name,
'custom_class' => $group->custom_class, 'custom_class' => $group->custom_class,
'active' => (bool) $group->active, 'default_block_class' => $group->default_block_class,
'active' => (bool) $group->active,
]; ];
} }
public function getDefaultData() public function getDefaultData()
{ {
return [ return [
'title' => '', 'title' => [],
'hook_name' => '', 'hook_name' => '',
'custom_class' => '', 'custom_class' => '',
'active' => true, 'default_block_class' => '',
'active' => true,
]; ];
} }
} }
+34 -16
View File
@@ -12,20 +12,25 @@ use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use PrestaShop\PrestaShop\Core\Form\ConfigurableFormChoiceProviderInterface; use PrestaShop\PrestaShop\Core\Form\ConfigurableFormChoiceProviderInterface;
use PrestaShopBundle\Form\Admin\Type\FormattedTextareaType;
use PrestaShopBundle\Form\Admin\Type\SwitchType; use PrestaShopBundle\Form\Admin\Type\SwitchType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
use Websmid\CustomHtml\Config\Config; use Websmid\CustomHtml\Config\Config;
class CustomHtmlBlockType extends AbstractType class CustomHtmlBlockType extends AbstractType
{ {
private $translator; private $translator;
private $locales;
private $groupChoiceProvider; private $groupChoiceProvider;
public function __construct( public function __construct(
TranslatorInterface $translator, TranslatorInterface $translator,
array $locales,
ConfigurableFormChoiceProviderInterface $groupChoiceProvider ConfigurableFormChoiceProviderInterface $groupChoiceProvider
) { ) {
$this->translator = $translator; $this->translator = $translator;
$this->locales = $locales;
$this->groupChoiceProvider = $groupChoiceProvider; $this->groupChoiceProvider = $groupChoiceProvider;
} }
@@ -33,17 +38,20 @@ class CustomHtmlBlockType extends AbstractType
{ {
$formBuilder $formBuilder
->add('id_ws_customhtml_group', ChoiceType::class, [ ->add('id_ws_customhtml_group', ChoiceType::class, [
'label' => $this->translator->trans('Group', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Group', [], 'Modules.Wscustomhtml.Admin'),
'choices' => $this->groupChoiceProvider->getChoices(), 'choices' => $this->groupChoiceProvider->getChoices(),
'required' => true, 'choice_attr' => $this->groupChoiceProvider->getChoicesAttributes(),
'required' => true,
]) ])
->add('type', ChoiceType::class, [ ->add('type', ChoiceType::class, [
'label' => $this->translator->trans('Block type', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Block type', [], 'Modules.Wscustomhtml.Admin'),
'choices' => array_flip(Config::BLOCK_TYPES), 'choices' => array_flip(Config::BLOCK_TYPES),
'required' => true, 'required' => true,
]) ])
->add('title', TextType::class, [ ->add('title', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => true, 'required' => true,
'row_attr' => ['class' => 'col-8'], 'row_attr' => ['class' => 'col-8'],
]) ])
@@ -52,10 +60,11 @@ class CustomHtmlBlockType extends AbstractType
'required' => false, 'required' => false,
'row_attr' => ['class' => 'col-3'], 'row_attr' => ['class' => 'col-3'],
]) ])
->add('content', TextareaType::class, [ ->add('content', TranslatableType::class, [
'type' => FormattedTextareaType::class,
'label' => $this->translator->trans('Content', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Content', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'attr' => ['class' => 'autoload_rte'],
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-html'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-html'],
]) ])
->add('image', FileType::class, [ ->add('image', FileType::class, [
@@ -83,6 +92,7 @@ class CustomHtmlBlockType extends AbstractType
'label' => $this->translator->trans('Slider mode', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Slider mode', [], 'Modules.Wscustomhtml.Admin'),
'choices' => array_flip(Config::SLIDER_MODES), 'choices' => array_flip(Config::SLIDER_MODES),
'required' => false, 'required' => false,
'help' => $this->translator->trans('"Mobile only": slider only on mobile, a static grid shows instead from tablet up.', [], 'Modules.Wscustomhtml.Admin'),
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-slider'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-slider'],
]) ])
->add('slides_per_view_mobile', NumberType::class, [ ->add('slides_per_view_mobile', NumberType::class, [
@@ -103,8 +113,8 @@ class CustomHtmlBlockType extends AbstractType
'label' => $this->translator->trans('Slides visible on desktop', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Slides visible on desktop', [], 'Modules.Wscustomhtml.Admin'),
'required' => false, 'required' => false,
'scale' => 2, 'scale' => 2,
'attr' => ['min' => 0, 'step' => '0.05'], 'attr' => ['min' => 0, 'step' => '0.05', 'placeholder' => $this->translator->trans('Auto', [], 'Modules.Wscustomhtml.Admin')],
'help' => $this->translator->trans('In "static grid on desktop" mode this is rounded to the nearest whole number of columns.', [], 'Modules.Wscustomhtml.Admin'), 'help' => $this->translator->trans('In "Mobile only" mode this is rounded to the nearest whole number of columns. Leave empty for an equal-width column.', [], 'Modules.Wscustomhtml.Admin'),
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-slider col-4'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-slider col-4'],
]) ])
->add('autoplay_delay', IntegerType::class, [ ->add('autoplay_delay', IntegerType::class, [
@@ -127,26 +137,34 @@ class CustomHtmlBlockType extends AbstractType
'help' => $this->translator->trans('0 means the alert never auto-dismisses; visitors can still close it manually.', [], 'Modules.Wscustomhtml.Admin'), 'help' => $this->translator->trans('0 means the alert never auto-dismisses; visitors can still close it manually.', [], 'Modules.Wscustomhtml.Admin'),
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-alert'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-alert'],
]) ])
->add('description', TextareaType::class, [ ->add('description', TranslatableType::class, [
'type' => TextareaType::class,
'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner customhtmlblock-type-alert'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner customhtmlblock-type-alert customhtmlblock-type-usp'],
]) ])
->add('extra_description', TextareaType::class, [ ->add('extra_description', TranslatableType::class, [
'type' => TextareaType::class,
'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner'],
]) ])
->add('link', TextType::class, [ ->add('link', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Link URL', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Link URL', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'attr' => ['placeholder' => 'https://example.com or /internal-page'], 'options' => ['attr' => ['placeholder' => 'https://example.com or /internal-page']],
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner customhtmlblock-type-usp customhtmlblock-type-alert col-6'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner customhtmlblock-type-usp customhtmlblock-type-alert'],
]) ])
->add('link_text', TextType::class, [ ->add('link_text', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Link text', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Link text', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'attr' => ['placeholder' => 'Learn more'], 'options' => ['attr' => ['placeholder' => 'Learn more']],
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-alert col-6'], 'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-alert col-6'],
]) ])
->add('custom_class', TextType::class, [ ->add('custom_class', TextType::class, [
+10 -3
View File
@@ -6,26 +6,33 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
class CustomHtmlFaqType extends AbstractType class CustomHtmlFaqType extends AbstractType
{ {
private $translator; private $translator;
private $locales;
public function __construct(TranslatorInterface $translator) public function __construct(TranslatorInterface $translator, array $locales)
{ {
$this->translator = $translator; $this->translator = $translator;
$this->locales = $locales;
} }
public function buildForm(FormBuilderInterface $formBuilder, array $options): void public function buildForm(FormBuilderInterface $formBuilder, array $options): void
{ {
$formBuilder $formBuilder
->add('question', TextType::class, [ ->add('question', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Question', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Question', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
]) ])
->add('answer', TextareaType::class, [ ->add('answer', TranslatableType::class, [
'type' => TextareaType::class,
'label' => $this->translator->trans('Answer', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Answer', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
]); ]);
} }
+14 -3
View File
@@ -6,22 +6,27 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use PrestaShopBundle\Form\Admin\Type\SwitchType; use PrestaShopBundle\Form\Admin\Type\SwitchType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
class CustomHtmlGroupType extends AbstractType class CustomHtmlGroupType extends AbstractType
{ {
private $translator; private $translator;
private $locales;
public function __construct(TranslatorInterface $translator) public function __construct(TranslatorInterface $translator, array $locales)
{ {
$this->translator = $translator; $this->translator = $translator;
$this->locales = $locales;
} }
public function buildForm(FormBuilderInterface $formBuilder, array $options): void public function buildForm(FormBuilderInterface $formBuilder, array $options): void
{ {
$formBuilder $formBuilder
->add('title', TextType::class, [ ->add('title', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => true, 'required' => true,
]) ])
->add('hook_name', TextType::class, [ ->add('hook_name', TextType::class, [
@@ -29,10 +34,16 @@ class CustomHtmlGroupType extends AbstractType
'required' => true, 'required' => true,
]) ])
->add('custom_class', TextType::class, [ ->add('custom_class', TextType::class, [
'label' => $this->translator->trans('Custom classes', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Custom group classes', [], 'Modules.Wscustomhtml.Admin'),
'required' => false, 'required' => false,
'attr' => ['placeholder' => 'col-md-6'], 'attr' => ['placeholder' => 'col-md-6'],
]) ])
->add('default_block_class', TextType::class, [
'label' => $this->translator->trans('Default block class', [], 'Modules.Wscustomhtml.Admin'),
'required' => false,
'attr' => ['placeholder' => 'col-12 col-lg-6 col-xl-5'],
'help' => $this->translator->trans('Applied to every block in this group automatically, in addition to that block\'s own custom classes. Useful when several blocks need the same column layout.', [], 'Modules.Wscustomhtml.Admin'),
])
->add('active', SwitchType::class, [ ->add('active', SwitchType::class, [
'label' => $this->translator->trans('Active', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Active', [], 'Modules.Wscustomhtml.Admin'),
'required' => false, 'required' => false,
+21 -8
View File
@@ -8,15 +8,18 @@ use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
class CustomHtmlSlideType extends AbstractType class CustomHtmlSlideType extends AbstractType
{ {
private $translator; private $translator;
private $locales;
public function __construct(TranslatorInterface $translator) public function __construct(TranslatorInterface $translator, array $locales)
{ {
$this->translator = $translator; $this->translator = $translator;
$this->locales = $locales;
} }
public function buildForm(FormBuilderInterface $formBuilder, array $options): void public function buildForm(FormBuilderInterface $formBuilder, array $options): void
@@ -25,27 +28,37 @@ class CustomHtmlSlideType extends AbstractType
->add('id', HiddenType::class, [ ->add('id', HiddenType::class, [
'required' => false, 'required' => false,
]) ])
->add('title', TextType::class, [ ->add('title', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Title', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
]) ])
->add('description', TextareaType::class, [ ->add('description', TranslatableType::class, [
'type' => TextareaType::class,
'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
]) ])
->add('extra_description', TextareaType::class, [ ->add('extra_description', TranslatableType::class, [
'type' => TextareaType::class,
'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
]) ])
->add('link', TextType::class, [ ->add('link', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Link URL', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Link URL', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'attr' => ['placeholder' => 'https://example.com or /internal-page'], 'options' => ['attr' => ['placeholder' => 'https://example.com or /internal-page']],
]) ])
->add('link_text', TextType::class, [ ->add('link_text', TranslatableType::class, [
'type' => TextType::class,
'label' => $this->translator->trans('Link text', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Link text', [], 'Modules.Wscustomhtml.Admin'),
'locales' => $this->locales,
'required' => false, 'required' => false,
'attr' => ['placeholder' => 'Learn more'], 'options' => ['attr' => ['placeholder' => 'Learn more']],
]) ])
->add('image', FileType::class, [ ->add('image', FileType::class, [
'label' => $this->translator->trans('Image', [], 'Modules.Wscustomhtml.Admin'), 'label' => $this->translator->trans('Image', [], 'Modules.Wscustomhtml.Admin'),
@@ -170,10 +170,17 @@ final class CustomHtmlBlockGridDefinitionFactory extends AbstractGridDefinitionF
'route_param_field' => 'id_ws_customhtml', 'route_param_field' => 'id_ws_customhtml',
'use_inline_display' => true, 'use_inline_display' => true,
'clickable_row' => true, 'clickable_row' => true,
'extra_route_params' => ['idGroup' => 'id_ws_customhtml_group'],
]) ])
) )
->add( ->add(
$this->buildDeleteAction('customhtmlblock_delete', 'idCustomHtmlBlock', 'id_ws_customhtml') $this->buildDeleteAction(
'customhtmlblock_delete',
'idCustomHtmlBlock',
'id_ws_customhtml',
'POST',
['idGroup' => 'id_ws_customhtml_group']
)
); );
} }
} }
@@ -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\ColumnCollection;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn; 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\PositionColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ToggleColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn; use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\DeleteActionTrait; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\DeleteActionTrait;
@@ -72,20 +73,20 @@ final class CustomHtmlGroupGridDefinitionFactory extends AbstractGridDefinitionF
->setName($this->trans('Hook', [], 'Modules.Wscustomhtml.Admin')) ->setName($this->trans('Hook', [], 'Modules.Wscustomhtml.Admin'))
->setOptions(['field' => 'hook_name']) ->setOptions(['field' => 'hook_name'])
) )
->add(
(new DataColumn('custom_class'))
->setName($this->trans('Custom classes', [], 'Modules.Wscustomhtml.Admin'))
->setOptions(['field' => 'custom_class'])
)
->add( ->add(
(new DataColumn('blocks_count')) (new DataColumn('blocks_count'))
->setName($this->trans('Blocks', [], 'Modules.Wscustomhtml.Admin')) ->setName($this->trans('Blocks', [], 'Modules.Wscustomhtml.Admin'))
->setOptions(['field' => 'blocks_count', 'sortable' => false]) ->setOptions(['field' => 'blocks_count', 'sortable' => false])
) )
->add( ->add(
(new DataColumn('active')) (new ToggleColumn('active'))
->setName($this->trans('Active', [], 'Admin.Global')) ->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( ->add(
(new PositionColumn('position')) (new PositionColumn('position'))
+25 -3
View File
@@ -11,6 +11,8 @@ use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder
{ {
private $contextLanguageId;
public function __construct( public function __construct(
Connection $connection, Connection $connection,
string $dbPrefix, string $dbPrefix,
@@ -22,6 +24,8 @@ final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder
Configuration $configuration Configuration $configuration
) { ) {
parent::__construct($connection, $dbPrefix); parent::__construct($connection, $dbPrefix);
$this->contextLanguageId = $contextLanguageId;
} }
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria) public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria)
@@ -31,8 +35,8 @@ final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder
$qb->select( $qb->select(
'wchb.`id_ws_customhtml`', 'wchb.`id_ws_customhtml`',
'wchb.`id_ws_customhtml_group`', 'wchb.`id_ws_customhtml_group`',
'wchb.`title`', 'wchbl.`title`',
'wchg.`title` AS group_title', 'wchgl.`title` AS group_title',
'wchb.`type`', 'wchb.`type`',
'wchb.`active`', 'wchb.`active`',
'wchb.`ordering`', 'wchb.`ordering`',
@@ -71,6 +75,18 @@ final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder
$this->dbPrefix . 'ws_customhtml_group', $this->dbPrefix . 'ws_customhtml_group',
'wchg', 'wchg',
'wchg.`id_ws_customhtml_group` = wchb.`id_ws_customhtml_group`' 'wchg.`id_ws_customhtml_group` = wchb.`id_ws_customhtml_group`'
)
->leftJoin(
'wchb',
$this->dbPrefix . 'ws_customhtml_group_lang',
'wchgl',
'wchgl.`id_ws_customhtml_group` = wchb.`id_ws_customhtml_group` AND wchgl.`id_lang` = ' . (int) $this->contextLanguageId
)
->leftJoin(
'wchb',
$this->dbPrefix . 'ws_customhtml_lang',
'wchbl',
'wchbl.`id_ws_customhtml` = wchb.`id_ws_customhtml` AND wchbl.`id_lang` = ' . (int) $this->contextLanguageId
); );
} }
@@ -93,8 +109,14 @@ final class CustomHtmlBlockQueryBuilder extends AbstractDoctrineQueryBuilder
continue; continue;
} }
if ($filterName === 'title') {
$qb->andWhere('wchbl.`title` LIKE :title')
->setParameter('title', '%' . pSQL($filterValue) . '%');
continue;
}
if ($filterName === 'group_title') { if ($filterName === 'group_title') {
$qb->andWhere('wchg.`title` LIKE :group_title') $qb->andWhere('wchgl.`title` LIKE :group_title')
->setParameter('group_title', '%' . pSQL($filterValue) . '%'); ->setParameter('group_title', '%' . pSQL($filterValue) . '%');
continue; continue;
} }
+18 -2
View File
@@ -11,6 +11,8 @@ use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
{ {
private $contextLanguageId;
public function __construct( public function __construct(
Connection $connection, Connection $connection,
string $dbPrefix, string $dbPrefix,
@@ -22,6 +24,8 @@ final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
Configuration $configuration Configuration $configuration
) { ) {
parent::__construct($connection, $dbPrefix); parent::__construct($connection, $dbPrefix);
$this->contextLanguageId = $contextLanguageId;
} }
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria) public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria)
@@ -30,7 +34,7 @@ final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
$qb->select( $qb->select(
'wchg.`id_ws_customhtml_group`', 'wchg.`id_ws_customhtml_group`',
'wchg.`title`', 'wchgl.`title`',
'wchg.`hook_name`', 'wchg.`hook_name`',
'wchg.`custom_class`', 'wchg.`custom_class`',
'wchg.`active`', 'wchg.`active`',
@@ -66,7 +70,13 @@ final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
{ {
return $this->connection return $this->connection
->createQueryBuilder() ->createQueryBuilder()
->from($this->dbPrefix . 'ws_customhtml_group', 'wchg'); ->from($this->dbPrefix . 'ws_customhtml_group', 'wchg')
->leftJoin(
'wchg',
$this->dbPrefix . 'ws_customhtml_group_lang',
'wchgl',
'wchgl.`id_ws_customhtml_group` = wchg.`id_ws_customhtml_group` AND wchgl.`id_lang` = ' . (int) $this->contextLanguageId
);
} }
private function applyFilters($qb, SearchCriteriaInterface $searchCriteria): void private function applyFilters($qb, SearchCriteriaInterface $searchCriteria): void
@@ -82,6 +92,12 @@ final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
continue; continue;
} }
if ($filterName === 'title') {
$qb->andWhere('wchgl.`title` LIKE :title')
->setParameter('title', '%' . pSQL($filterValue) . '%');
continue;
}
$qb->andWhere('wchg.`' . $filterName . '` LIKE :' . $filterName) $qb->andWhere('wchg.`' . $filterName . '` LIKE :' . $filterName)
->setParameter($filterName, '%' . pSQL($filterValue) . '%'); ->setParameter($filterName, '%' . pSQL($filterValue) . '%');
} }
+21 -18
View File
@@ -77,18 +77,19 @@ class CustomHtmlBlock extends ObjectModel
public $date_upd; public $date_upd;
public static $definition = [ public static $definition = [
'table' => 'ws_customhtml', 'table' => 'ws_customhtml',
'primary' => 'id_ws_customhtml', 'primary' => 'id_ws_customhtml',
'fields' => [ 'multilang' => true,
'fields' => [
'id_ws_customhtml_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_ws_customhtml_group' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256], 'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256, 'lang' => true],
'type' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32], 'type' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32],
'content' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'], 'content' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'lang' => true],
'custom_class' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128], 'custom_class' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128],
'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024], 'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024], 'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512], 'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512, 'lang' => true],
'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128], 'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128, 'lang' => true],
'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255], 'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255],
'alert_type' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 16], 'alert_type' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 16],
'timeout' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => false], 'timeout' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => false],
@@ -119,7 +120,7 @@ class CustomHtmlBlock extends ObjectModel
return _MODULE_DIR_ . 'ws_customhtml/views/img/banners/' . $filename; return _MODULE_DIR_ . 'ws_customhtml/views/img/banners/' . $filename;
} }
public static function getActiveByGroupIds(array $groupIds): array public static function getActiveByGroupIds(array $groupIds, int $idLang): array
{ {
$groupIds = array_map('intval', $groupIds); $groupIds = array_map('intval', $groupIds);
@@ -128,14 +129,16 @@ class CustomHtmlBlock extends ObjectModel
} }
$result = Db::getInstance()->executeS( $result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `id_ws_customhtml_group`, `title`, `type`, `content`, `custom_class`, 'SELECT wch.`id_ws_customhtml`, wch.`id_ws_customhtml_group`, wchl.`title`, wch.`type`, wchl.`content`, wch.`custom_class`,
`description`, `extra_description`, `link`, `link_text`, `image`, `alert_type`, `timeout`, wchl.`description`, wchl.`extra_description`, wchl.`link`, wchl.`link_text`, wch.`image`, wch.`alert_type`, wch.`timeout`,
`slider_mode`, `slides_per_view_mobile`, `slides_per_view_tablet`, `slides_per_view_desktop`, `autoplay_delay`, wch.`slider_mode`, wch.`slides_per_view_mobile`, wch.`slides_per_view_tablet`, wch.`slides_per_view_desktop`, wch.`autoplay_delay`,
`active`, `show_title`, `ordering` wch.`active`, wch.`show_title`, wch.`ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml` FROM `' . _DB_PREFIX_ . 'ws_customhtml` wch
WHERE `id_ws_customhtml_group` IN (' . implode(',', $groupIds) . ') LEFT JOIN `' . _DB_PREFIX_ . 'ws_customhtml_lang` wchl
AND `active` = 1 ON wchl.`id_ws_customhtml` = wch.`id_ws_customhtml` AND wchl.`id_lang` = ' . (int) $idLang . '
ORDER BY `ordering` ASC' WHERE wch.`id_ws_customhtml_group` IN (' . implode(',', $groupIds) . ')
AND wch.`active` = 1
ORDER BY wch.`ordering` ASC'
); );
$blocksByGroup = []; $blocksByGroup = [];
+37 -8
View File
@@ -29,27 +29,56 @@ class CustomHtmlFaq extends ObjectModel
public $date_upd; public $date_upd;
public static $definition = [ public static $definition = [
'table' => 'ws_customhtml_faq', 'table' => 'ws_customhtml_faq',
'primary' => 'id_ws_customhtml_faq', 'primary' => 'id_ws_customhtml_faq',
'fields' => [ 'multilang' => true,
'fields' => [
'id_ws_customhtml' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_ws_customhtml' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'question' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 512], 'question' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 512, 'lang' => true],
'answer' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'], 'answer' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'lang' => true],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], 'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
], ],
]; ];
/**
* Admin use — loads every language into lang fields as [id_lang => value] arrays.
*/
public static function getByBlockId(int $idBlock): array public static function getByBlockId(int $idBlock): array
{ {
$result = Db::getInstance()->executeS( $ids = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_faq`, `question`, `answer`, `ordering` 'SELECT `id_ws_customhtml_faq` FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq`
WHERE `id_ws_customhtml` = ' . (int) $idBlock . ' WHERE `id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY `ordering` ASC' ORDER BY `ordering` ASC'
); );
return array_map(static function (array $row) {
$faq = new self((int) $row['id_ws_customhtml_faq']);
return [
'id_ws_customhtml_faq' => (int) $faq->id,
'question' => $faq->question,
'answer' => $faq->answer,
'ordering' => (int) $faq->ordering,
];
}, $ids ?: []);
}
/**
* Front-end use — resolves lang fields to plain strings for one language.
*/
public static function getByBlockIdForLang(int $idBlock, int $idLang): array
{
$result = Db::getInstance()->executeS(
'SELECT wcf.`id_ws_customhtml_faq`, wcfl.`question`, wcfl.`answer`, wcf.`ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq` wcf
LEFT JOIN `' . _DB_PREFIX_ . 'ws_customhtml_faq_lang` wcfl
ON wcfl.`id_ws_customhtml_faq` = wcf.`id_ws_customhtml_faq` AND wcfl.`id_lang` = ' . (int) $idLang . '
WHERE wcf.`id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY wcf.`ordering` ASC'
);
return $result ?: []; return $result ?: [];
} }
+10 -5
View File
@@ -19,6 +19,9 @@ class CustomHtmlGroup extends ObjectModel
/** @var string */ /** @var string */
public $custom_class = ''; public $custom_class = '';
/** @var string */
public $default_block_class = '';
/** @var int */ /** @var int */
public $active = 1; public $active = 1;
@@ -32,12 +35,14 @@ class CustomHtmlGroup extends ObjectModel
public $date_upd; public $date_upd;
public static $definition = [ public static $definition = [
'table' => 'ws_customhtml_group', 'table' => 'ws_customhtml_group',
'primary' => 'id_ws_customhtml_group', 'primary' => 'id_ws_customhtml_group',
'fields' => [ 'multilang' => true,
'fields' => [
'hook_name' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64], 'hook_name' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256], 'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256, 'lang' => true],
'custom_class' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128], 'custom_class' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128],
'default_block_class' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128],
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'], 'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
@@ -48,7 +53,7 @@ class CustomHtmlGroup extends ObjectModel
public static function getActiveByHookName(string $hookName): array public static function getActiveByHookName(string $hookName): array
{ {
$result = Db::getInstance()->executeS( $result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_group`, `title`, `active`, `custom_class`, `ordering` 'SELECT `id_ws_customhtml_group`, `active`, `custom_class`, `default_block_class`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`
WHERE `hook_name` = \'' . pSQL($hookName) . '\' WHERE `hook_name` = \'' . pSQL($hookName) . '\'
AND `active` = 1 AND `active` = 1
+45 -11
View File
@@ -41,15 +41,16 @@ class CustomHtmlSlide extends ObjectModel
public $date_upd; public $date_upd;
public static $definition = [ public static $definition = [
'table' => 'ws_customhtml_slide', 'table' => 'ws_customhtml_slide',
'primary' => 'id_ws_customhtml_slide', 'primary' => 'id_ws_customhtml_slide',
'fields' => [ 'multilang' => true,
'fields' => [
'id_ws_customhtml' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true], 'id_ws_customhtml' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true],
'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 256], 'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 256, 'lang' => true],
'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024], 'description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024], 'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024, 'lang' => true],
'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512], 'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512, 'lang' => true],
'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128], 'link_text' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 128, 'lang' => true],
'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255], 'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
@@ -57,15 +58,48 @@ class CustomHtmlSlide extends ObjectModel
], ],
]; ];
/**
* Admin use — loads every language into lang fields as [id_lang => value] arrays.
*/
public static function getByBlockId(int $idBlock): array public static function getByBlockId(int $idBlock): array
{ {
$result = Db::getInstance()->executeS( $ids = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_slide`, `title`, `description`, `extra_description`, `link`, `link_text`, `image`, `ordering` 'SELECT `id_ws_customhtml_slide` FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide`
WHERE `id_ws_customhtml` = ' . (int) $idBlock . ' WHERE `id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY `ordering` ASC' ORDER BY `ordering` ASC'
); );
return array_map(static function (array $row) {
$slide = new self((int) $row['id_ws_customhtml_slide']);
return [
'id_ws_customhtml_slide' => (int) $slide->id,
'title' => $slide->title,
'description' => $slide->description,
'extra_description' => $slide->extra_description,
'link' => $slide->link,
'link_text' => $slide->link_text,
'image' => $slide->image,
'ordering' => (int) $slide->ordering,
];
}, $ids ?: []);
}
/**
* Front-end use — resolves lang fields to plain strings for one language.
*/
public static function getByBlockIdForLang(int $idBlock, int $idLang): array
{
$result = Db::getInstance()->executeS(
'SELECT wcs.`id_ws_customhtml_slide`, wcsl.`title`, wcsl.`description`, wcsl.`extra_description`,
wcsl.`link`, wcsl.`link_text`, wcs.`image`, wcs.`ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide` wcs
LEFT JOIN `' . _DB_PREFIX_ . 'ws_customhtml_slide_lang` wcsl
ON wcsl.`id_ws_customhtml_slide` = wcs.`id_ws_customhtml_slide` AND wcsl.`id_lang` = ' . (int) $idLang . '
WHERE wcs.`id_ws_customhtml` = ' . (int) $idBlock . '
ORDER BY wcs.`ordering` ASC'
);
return $result ?: []; return $result ?: [];
} }
+25 -17
View File
@@ -49,7 +49,8 @@ trait DisplayHooks
public function getWidgetVariables($hookName = null, array $configuration = []) public function getWidgetVariables($hookName = null, array $configuration = [])
{ {
$groupList = $this->loadActiveGroupsWithBlocks((string) $hookName); $idLang = (int) Context::getContext()->language->id;
$groupList = $this->loadActiveGroupsWithBlocks((string) $hookName, $idLang);
if (empty($groupList)) { if (empty($groupList)) {
return []; return [];
@@ -61,7 +62,7 @@ trait DisplayHooks
]; ];
} }
private function loadActiveGroupsWithBlocks(string $hookName): array private function loadActiveGroupsWithBlocks(string $hookName, int $idLang): array
{ {
$groups = CustomHtmlGroup::getActiveByHookName($hookName); $groups = CustomHtmlGroup::getActiveByHookName($hookName);
@@ -69,10 +70,10 @@ trait DisplayHooks
return []; return [];
} }
$blocksByGroup = CustomHtmlBlock::getActiveByGroupIds(array_column($groups, 'id_ws_customhtml_group')); $blocksByGroup = CustomHtmlBlock::getActiveByGroupIds(array_column($groups, 'id_ws_customhtml_group'), $idLang);
$blocksByGroup = $this->attachFaqsToBlocks($blocksByGroup); $blocksByGroup = $this->attachFaqsToBlocks($blocksByGroup, $idLang);
$blocksByGroup = $this->attachImageUrls($blocksByGroup); $blocksByGroup = $this->attachImageUrls($blocksByGroup);
$blocksByGroup = $this->attachSlidesToBlocks($blocksByGroup); $blocksByGroup = $this->attachSlidesToBlocks($blocksByGroup, $idLang);
$groups = array_map(static function (array $group) use ($blocksByGroup) { $groups = array_map(static function (array $group) use ($blocksByGroup) {
$group['blocks'] = $blocksByGroup[(int) $group['id_ws_customhtml_group']] ?? []; $group['blocks'] = $blocksByGroup[(int) $group['id_ws_customhtml_group']] ?? [];
@@ -85,12 +86,12 @@ trait DisplayHooks
})); }));
} }
private function attachFaqsToBlocks(array $blocksByGroup): array private function attachFaqsToBlocks(array $blocksByGroup, int $idLang): array
{ {
return array_map(static function (array $blocks) { return array_map(static function (array $blocks) use ($idLang) {
return array_map(static function (array $block) { return array_map(static function (array $block) use ($idLang) {
if ($block['type'] === 'faq') { if ($block['type'] === 'faq') {
$block['faqs'] = CustomHtmlFaq::getByBlockId((int) $block['id_ws_customhtml']); $block['faqs'] = CustomHtmlFaq::getByBlockIdForLang((int) $block['id_ws_customhtml'], $idLang);
} }
return $block; return $block;
@@ -111,12 +112,12 @@ trait DisplayHooks
}, $blocksByGroup); }, $blocksByGroup);
} }
private function attachSlidesToBlocks(array $blocksByGroup): array private function attachSlidesToBlocks(array $blocksByGroup, int $idLang): array
{ {
return array_map(function (array $blocks) { return array_map(function (array $blocks) use ($idLang) {
return array_map(function (array $block) { return array_map(function (array $block) use ($idLang) {
if ($block['type'] === 'slider') { if ($block['type'] === 'slider') {
$block['slides'] = $this->loadSlidesForBlock((int) $block['id_ws_customhtml']); $block['slides'] = $this->loadSlidesForBlock((int) $block['id_ws_customhtml'], $idLang);
$block['slider_config'] = $this->buildSliderConfig($block); $block['slider_config'] = $this->buildSliderConfig($block);
$block['slider_desktop_column_width'] = $this->buildSliderDesktopColumnWidth($block); $block['slider_desktop_column_width'] = $this->buildSliderDesktopColumnWidth($block);
} }
@@ -126,14 +127,14 @@ trait DisplayHooks
}, $blocksByGroup); }, $blocksByGroup);
} }
private function loadSlidesForBlock(int $idBlock): array private function loadSlidesForBlock(int $idBlock, int $idLang): array
{ {
return array_map(static function (array $slide) { return array_map(static function (array $slide) {
$slide['image_url'] = CustomHtmlBlock::getBannerImageUrl($slide['image']); $slide['image_url'] = CustomHtmlBlock::getBannerImageUrl($slide['image']);
$slide['show_title'] = true; $slide['show_title'] = true;
return $slide; return $slide;
}, CustomHtmlSlide::getByBlockId($idBlock)); }, CustomHtmlSlide::getByBlockIdForLang($idBlock, $idLang));
} }
private function buildSliderConfig(array $block): string private function buildSliderConfig(array $block): string
@@ -152,8 +153,11 @@ trait DisplayHooks
} else { } else {
$config['breakpoints'] = [ $config['breakpoints'] = [
768 => ['slidesPerView' => (float) $block['slides_per_view_tablet']], 768 => ['slidesPerView' => (float) $block['slides_per_view_tablet']],
992 => ['slidesPerView' => (float) $block['slides_per_view_desktop']],
]; ];
if ((float) $block['slides_per_view_desktop'] > 0) {
$config['breakpoints'][992] = ['slidesPerView' => (float) $block['slides_per_view_desktop']];
}
} }
if ((int) $block['autoplay_delay'] > 0) { if ((int) $block['autoplay_delay'] > 0) {
@@ -167,8 +171,12 @@ trait DisplayHooks
return json_encode($config); return json_encode($config);
} }
private function buildSliderDesktopColumnWidth(array $block): string private function buildSliderDesktopColumnWidth(array $block): ?string
{ {
if ((float) $block['slides_per_view_desktop'] <= 0) {
return null;
}
$columns = max(1, (int) round((float) $block['slides_per_view_desktop'])); $columns = max(1, (int) round((float) $block['slides_per_view_desktop']));
return round(100 / $columns, 4) . '%'; return round(100 / $columns, 4) . '%';
+47 -14
View File
@@ -49,8 +49,8 @@ trait Install
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_group ( CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_group (
`id_ws_customhtml_group` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_ws_customhtml_group` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`hook_name` VARCHAR(64) NOT NULL, `hook_name` VARCHAR(64) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`custom_class` VARCHAR(128) NOT NULL DEFAULT \'\', `custom_class` VARCHAR(128) NOT NULL DEFAULT \'\',
`default_block_class` VARCHAR(128) NOT NULL DEFAULT \'\',
`active` TINYINT(1) NOT NULL DEFAULT 1, `active` TINYINT(1) NOT NULL DEFAULT 1,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL, `date_add` DATETIME NOT NULL,
@@ -58,18 +58,21 @@ trait Install
); );
'; ';
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_group_lang (
`id_ws_customhtml_group` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml_group`, `id_lang`)
);
';
$sqlToExec[] = ' $sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml ( CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml (
`id_ws_customhtml` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_ws_customhtml` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_ws_customhtml_group` INT(11) NOT NULL, `id_ws_customhtml_group` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`type` VARCHAR(32) NOT NULL DEFAULT \'html\', `type` VARCHAR(32) NOT NULL DEFAULT \'html\',
`content` LONGTEXT,
`custom_class` VARCHAR(128) NOT NULL DEFAULT \'\', `custom_class` VARCHAR(128) NOT NULL DEFAULT \'\',
`description` TEXT,
`extra_description` TEXT,
`link` VARCHAR(512) NOT NULL DEFAULT \'\',
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
`image` VARCHAR(255) NOT NULL DEFAULT \'\', `image` VARCHAR(255) NOT NULL DEFAULT \'\',
`alert_type` VARCHAR(16) NOT NULL DEFAULT \'info\', `alert_type` VARCHAR(16) NOT NULL DEFAULT \'info\',
`timeout` INT(11) NOT NULL DEFAULT 0, `timeout` INT(11) NOT NULL DEFAULT 0,
@@ -87,12 +90,24 @@ trait Install
); );
'; ';
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_lang (
`id_ws_customhtml` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`content` LONGTEXT,
`description` TEXT,
`extra_description` TEXT,
`link` VARCHAR(512) NOT NULL DEFAULT \'\',
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml`, `id_lang`)
);
';
$sqlToExec[] = ' $sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_faq ( CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_faq (
`id_ws_customhtml_faq` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_ws_customhtml_faq` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_ws_customhtml` INT(11) NOT NULL, `id_ws_customhtml` INT(11) NOT NULL,
`question` VARCHAR(512) NOT NULL DEFAULT \'\',
`answer` TEXT,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL, `date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL, `date_upd` DATETIME NOT NULL,
@@ -100,15 +115,20 @@ trait Install
); );
'; ';
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_faq_lang (
`id_ws_customhtml_faq` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`question` VARCHAR(512) NOT NULL DEFAULT \'\',
`answer` TEXT,
PRIMARY KEY (`id_ws_customhtml_faq`, `id_lang`)
);
';
$sqlToExec[] = ' $sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_slide ( CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_slide (
`id_ws_customhtml_slide` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `id_ws_customhtml_slide` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_ws_customhtml` INT(11) NOT NULL, `id_ws_customhtml` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`description` TEXT,
`extra_description` TEXT,
`link` VARCHAR(512) NOT NULL DEFAULT \'\',
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
`image` VARCHAR(255) NOT NULL DEFAULT \'\', `image` VARCHAR(255) NOT NULL DEFAULT \'\',
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL, `date_add` DATETIME NOT NULL,
@@ -117,6 +137,19 @@ trait Install
); );
'; ';
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_slide_lang (
`id_ws_customhtml_slide` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`description` TEXT,
`extra_description` TEXT,
`link` VARCHAR(512) NOT NULL DEFAULT \'\',
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml_slide`, `id_lang`)
);
';
foreach ($sqlToExec as $sqlBlock) { foreach ($sqlToExec as $sqlBlock) {
Db::getInstance()->execute(trim($sqlBlock)); Db::getInstance()->execute(trim($sqlBlock));
} }
@@ -0,0 +1,10 @@
{if !empty($block.link)}<a href="{$block.link|escape:'html':'UTF-8'}">{/if}
<p class="h1 usp__name text-center">
<span>{$block.title|escape:'html':'UTF-8'}</span>
</p>
{if !empty($block.description)}
<p class="usp__description text-center">
{$block.description|escape:'html':'UTF-8'|nl2br}
</p>
{/if}
{if !empty($block.link)}</a>{/if}
+11
View File
@@ -0,0 +1,11 @@
{if !empty($block.link)}<a href="{$block.link|escape:'html':'UTF-8'}">{/if}
<small class="uppercase-mono-red">/{$iteration|string_format:"%02d"}</small>
<p class="h3 font-default usp__name mt2 mt-lg-3">
<span>{$block.title|escape:'html':'UTF-8'}</span>
</p>
{if !empty($block.description)}
<p class="usp__description">
{$block.description|escape:'html':'UTF-8'|nl2br}
</p>
{/if}
{if !empty($block.link)}</a>{/if}
+21
View File
@@ -0,0 +1,21 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_19_0($module)
{
$existing = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` LIKE \'default_block_class\''
);
if (!empty($existing)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_group`
ADD COLUMN `default_block_class` VARCHAR(128) NOT NULL DEFAULT \'\' AFTER `custom_class`'
);
}
+88
View File
@@ -0,0 +1,88 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_20_0($module)
{
if (!createGroupLangTable()) {
return false;
}
if (!migrateGroupTitlesToLangTable()) {
return false;
}
return dropGroupTitleColumn();
}
function createGroupLangTable(): bool
{
return Db::getInstance()->execute(
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_group_lang` (
`id_ws_customhtml_group` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml_group`, `id_lang`)
);'
);
}
function migrateGroupTitlesToLangTable(): bool
{
$groupColumns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` LIKE \'title\''
);
if (empty($groupColumns)) {
// Already migrated in a previous run of this upgrade.
return true;
}
$groups = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_group`, `title` FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`'
);
$languages = Language::getLanguages(false);
foreach ($groups as $group) {
foreach ($languages as $language) {
$existing = Db::getInstance()->executeS(
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_group_lang`
WHERE `id_ws_customhtml_group` = ' . (int) $group['id_ws_customhtml_group'] . '
AND `id_lang` = ' . (int) $language['id_lang']
);
if (!empty($existing)) {
continue;
}
$result = Db::getInstance()->insert('ws_customhtml_group_lang', [
'id_ws_customhtml_group' => (int) $group['id_ws_customhtml_group'],
'id_lang' => (int) $language['id_lang'],
'title' => pSQL($group['title']),
]);
if (!$result) {
return false;
}
}
}
return true;
}
function dropGroupTitleColumn(): bool
{
$groupColumns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` LIKE \'title\''
);
if (empty($groupColumns)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_group` DROP COLUMN `title`'
);
}
+102
View File
@@ -0,0 +1,102 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_21_0($module)
{
if (!createBlockLangTable()) {
return false;
}
if (!migrateBlockFieldsToLangTable()) {
return false;
}
return dropBlockLangColumns();
}
function createBlockLangTable(): bool
{
return Db::getInstance()->execute(
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_lang` (
`id_ws_customhtml` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`content` LONGTEXT,
`description` TEXT,
`extra_description` TEXT,
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml`, `id_lang`)
);'
);
}
function migrateBlockFieldsToLangTable(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'title\''
);
if (empty($columns)) {
// Already migrated in a previous run of this upgrade.
return true;
}
$blocks = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `title`, `content`, `description`, `extra_description`, `link_text`
FROM `' . _DB_PREFIX_ . 'ws_customhtml`'
);
$languages = Language::getLanguages(false);
foreach ($blocks as $block) {
foreach ($languages as $language) {
$existing = Db::getInstance()->executeS(
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_lang`
WHERE `id_ws_customhtml` = ' . (int) $block['id_ws_customhtml'] . '
AND `id_lang` = ' . (int) $language['id_lang']
);
if (!empty($existing)) {
continue;
}
$result = Db::getInstance()->insert('ws_customhtml_lang', [
'id_ws_customhtml' => (int) $block['id_ws_customhtml'],
'id_lang' => (int) $language['id_lang'],
'title' => pSQL($block['title']),
'content' => pSQL($block['content'], true),
'description' => pSQL($block['description']),
'extra_description' => pSQL($block['extra_description']),
'link_text' => pSQL($block['link_text']),
]);
if (!$result) {
return false;
}
}
}
return true;
}
function dropBlockLangColumns(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'title\''
);
if (empty($columns)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml`
DROP COLUMN `title`,
DROP COLUMN `content`,
DROP COLUMN `description`,
DROP COLUMN `extra_description`,
DROP COLUMN `link_text`'
);
}
+79
View File
@@ -0,0 +1,79 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_22_0($module)
{
if (!addLinkColumnToLangTable()) {
return false;
}
if (!migrateBlockLinkToLangTable()) {
return false;
}
return dropBlockLinkColumn();
}
function addLinkColumnToLangTable(): bool
{
$existing = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_lang` LIKE \'link\''
);
if (!empty($existing)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_lang`
ADD COLUMN `link` VARCHAR(512) NOT NULL DEFAULT \'\' AFTER `extra_description`'
);
}
function migrateBlockLinkToLangTable(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'link\''
);
if (empty($columns)) {
// Already migrated in a previous run of this upgrade.
return true;
}
$blocks = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `link` FROM `' . _DB_PREFIX_ . 'ws_customhtml`'
);
foreach ($blocks as $block) {
$result = Db::getInstance()->update(
'ws_customhtml_lang',
['link' => pSQL($block['link'])],
'`id_ws_customhtml` = ' . (int) $block['id_ws_customhtml']
);
if (!$result) {
return false;
}
}
return true;
}
function dropBlockLinkColumn(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml` LIKE \'link\''
);
if (empty($columns)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml` DROP COLUMN `link`'
);
}
+102
View File
@@ -0,0 +1,102 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_23_0($module)
{
if (!createSlideLangTable()) {
return false;
}
if (!migrateSlideFieldsToLangTable()) {
return false;
}
return dropSlideLangColumns();
}
function createSlideLangTable(): bool
{
return Db::getInstance()->execute(
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_slide_lang` (
`id_ws_customhtml_slide` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`description` TEXT,
`extra_description` TEXT,
`link` VARCHAR(512) NOT NULL DEFAULT \'\',
`link_text` VARCHAR(128) NOT NULL DEFAULT \'\',
PRIMARY KEY (`id_ws_customhtml_slide`, `id_lang`)
);'
);
}
function migrateSlideFieldsToLangTable(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide` LIKE \'title\''
);
if (empty($columns)) {
// Already migrated in a previous run of this upgrade.
return true;
}
$slides = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_slide`, `title`, `description`, `extra_description`, `link`, `link_text`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide`'
);
$languages = Language::getLanguages(false);
foreach ($slides as $slide) {
foreach ($languages as $language) {
$existing = Db::getInstance()->executeS(
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide_lang`
WHERE `id_ws_customhtml_slide` = ' . (int) $slide['id_ws_customhtml_slide'] . '
AND `id_lang` = ' . (int) $language['id_lang']
);
if (!empty($existing)) {
continue;
}
$result = Db::getInstance()->insert('ws_customhtml_slide_lang', [
'id_ws_customhtml_slide' => (int) $slide['id_ws_customhtml_slide'],
'id_lang' => (int) $language['id_lang'],
'title' => pSQL($slide['title']),
'description' => pSQL($slide['description']),
'extra_description' => pSQL($slide['extra_description']),
'link' => pSQL($slide['link']),
'link_text' => pSQL($slide['link_text']),
]);
if (!$result) {
return false;
}
}
}
return true;
}
function dropSlideLangColumns(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_slide` LIKE \'title\''
);
if (empty($columns)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_slide`
DROP COLUMN `title`,
DROP COLUMN `description`,
DROP COLUMN `extra_description`,
DROP COLUMN `link`,
DROP COLUMN `link_text`'
);
}
+93
View File
@@ -0,0 +1,93 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_24_0($module)
{
if (!createFaqLangTable()) {
return false;
}
if (!migrateFaqFieldsToLangTable()) {
return false;
}
return dropFaqLangColumns();
}
function createFaqLangTable(): bool
{
return Db::getInstance()->execute(
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'ws_customhtml_faq_lang` (
`id_ws_customhtml_faq` INT(11) NOT NULL,
`id_lang` INT(11) NOT NULL,
`question` VARCHAR(512) NOT NULL DEFAULT \'\',
`answer` TEXT,
PRIMARY KEY (`id_ws_customhtml_faq`, `id_lang`)
);'
);
}
function migrateFaqFieldsToLangTable(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq` LIKE \'question\''
);
if (empty($columns)) {
// Already migrated in a previous run of this upgrade.
return true;
}
$faqs = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml_faq`, `question`, `answer`
FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq`'
);
$languages = Language::getLanguages(false);
foreach ($faqs as $faq) {
foreach ($languages as $language) {
$existing = Db::getInstance()->executeS(
'SELECT 1 FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq_lang`
WHERE `id_ws_customhtml_faq` = ' . (int) $faq['id_ws_customhtml_faq'] . '
AND `id_lang` = ' . (int) $language['id_lang']
);
if (!empty($existing)) {
continue;
}
$result = Db::getInstance()->insert('ws_customhtml_faq_lang', [
'id_ws_customhtml_faq' => (int) $faq['id_ws_customhtml_faq'],
'id_lang' => (int) $language['id_lang'],
'question' => pSQL($faq['question']),
'answer' => pSQL($faq['answer'], true),
]);
if (!$result) {
return false;
}
}
}
return true;
}
function dropFaqLangColumns(): bool
{
$columns = Db::getInstance()->executeS(
'SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'ws_customhtml_faq` LIKE \'question\''
);
if (empty($columns)) {
return true;
}
return Db::getInstance()->execute(
'ALTER TABLE `' . _DB_PREFIX_ . 'ws_customhtml_faq`
DROP COLUMN `question`,
DROP COLUMN `answer`'
);
}
+10 -6
View File
@@ -7,6 +7,7 @@
padding: 2rem; padding: 2rem;
bottom: 0px; bottom: 0px;
position: absolute; position: absolute;
z-index: 2;
} }
.customhtml-banner-title { .customhtml-banner-title {
@@ -18,13 +19,16 @@
margin-bottom: 1rem; margin-bottom: 1rem;
} }
/* .customhtml-banner-image--gradient { .customhtml-banner-image {
width: 100%; position: relative;
height: 100%; }
.customhtml-banner-image--gradient {
position: absolute; position: absolute;
background: transparent linear-gradient(180deg, #27272777 0%, #272727 100%) inset: 0;
0% 0% no-repeat padding-box; pointer-events: none;
} */ z-index: 1;
}
/* Alert */ /* Alert */
.customhtml-alert { .customhtml-alert {
max-height: 500px; max-height: 500px;
+16
View File
@@ -1,6 +1,8 @@
$(document).ready(function () { $(document).ready(function () {
window.prestashop.component.initComponents([ window.prestashop.component.initComponents([
'TinyMCEEditor', 'TinyMCEEditor',
'TranslatableField',
'TranslatableInput',
]); ]);
function toggleBlockTypeFields() { function toggleBlockTypeFields() {
@@ -18,6 +20,20 @@ $(document).ready(function () {
$('#custom_html_block_type').on('change', toggleBlockTypeFields); $('#custom_html_block_type').on('change', toggleBlockTypeFields);
toggleBlockTypeFields(); toggleBlockTypeFields();
function toggleGroupDefaultClassHint() {
var hint = $('#customhtmlblock-group-default-class-hint');
var defaultClass = $('#custom_html_block_id_ws_customhtml_group option:selected').data('defaultBlockClass');
if (defaultClass) {
hint.text(hint.data('template').replace('%s%', defaultClass)).show();
} else {
hint.hide();
}
}
$('#custom_html_block_id_ws_customhtml_group').on('change', toggleGroupDefaultClassHint);
toggleGroupDefaultClassHint();
function initRepeater(containerSelector, addButtonSelector, itemClass, removeButtonClass) { function initRepeater(containerSelector, addButtonSelector, itemClass, removeButtonClass) {
var container = $(containerSelector); var container = $(containerSelector);
var removeLabel = container.data('removeLabel'); var removeLabel = container.data('removeLabel');
+6
View File
@@ -0,0 +1,6 @@
$(document).ready(function () {
window.prestashop.component.initComponents([
'TranslatableField',
'TranslatableInput',
]);
});
@@ -109,17 +109,20 @@
{{ form_row(customHtmlBlockForm.timeout) }} {{ form_row(customHtmlBlockForm.timeout) }}
{{ form_row(customHtmlBlockForm.description) }} {{ form_row(customHtmlBlockForm.description) }}
{{ form_row(customHtmlBlockForm.extra_description) }} {{ form_row(customHtmlBlockForm.extra_description) }}
<div class="row"> {{ form_row(customHtmlBlockForm.link) }}
{{ form_row(customHtmlBlockForm.link) }} {{ form_row(customHtmlBlockForm.link_text) }}
{{ form_row(customHtmlBlockForm.link_text) }}
</div>
<p
id="customhtmlblock-group-default-class-hint"
class="alert alert-warning"
data-template="{{ 'The group that this block belongs to applies the classes "%s%" to every block. Edit the group to change this - it is stored under the "Default block class" input.'|trans({}, 'Modules.Wscustomhtml.Admin')|e('html_attr') }}"
></p>
{{ form_row(customHtmlBlockForm.custom_class) }} {{ form_row(customHtmlBlockForm.custom_class) }}
{{ form_row(customHtmlBlockForm.active) }} {{ form_row(customHtmlBlockForm.active) }}
{{ form_rest(customHtmlBlockForm) }} {{ form_rest(customHtmlBlockForm) }}
</div> </div>
<div class="card-footer"> <div class="card-footer">
<a href="{{ path('customhtmlblock_index') }}" class="btn btn-outline-secondary"> <a href="{{ path('customhtmlblock_index', idGroup is defined and idGroup ? {'idGroup': idGroup} : {}) }}" class="btn btn-outline-secondary">
{{ 'Cancel'|trans({}, 'Admin.Actions') }} {{ 'Cancel'|trans({}, 'Admin.Actions') }}
</a> </a>
<button class="btn btn-primary float-right"> <button class="btn btn-primary float-right">
@@ -17,6 +17,9 @@
{{ 'Cancel'|trans({}, 'Admin.Actions') }} {{ 'Cancel'|trans({}, 'Admin.Actions') }}
</a> </a>
{% if idCustomHtmlGroup is defined %} {% if idCustomHtmlGroup is defined %}
<a href="{{ path('customhtmlblock_index', {'idGroup': idCustomHtmlGroup}) }}" class="btn btn-outline-primary">
{{ 'View blocks'|trans({}, 'Modules.Wscustomhtml.Admin') }}
</a>
<a href="{{ path('customhtmlblock_create', {'idGroup': idCustomHtmlGroup}) }}" class="btn btn-outline-primary"> <a href="{{ path('customhtmlblock_create', {'idGroup': idCustomHtmlGroup}) }}" class="btn btn-outline-primary">
{{ 'Add block'|trans({}, 'Modules.Wscustomhtml.Admin') }} {{ 'Add block'|trans({}, 'Modules.Wscustomhtml.Admin') }}
</a> </a>
@@ -5,3 +5,8 @@
{% include '@Modules/ws_customhtml/views/templates/admin/form/blocks/group_form.html.twig' %} {% include '@Modules/ws_customhtml/views/templates/admin/form/blocks/group_form.html.twig' %}
{% endblock %} {% endblock %}
{% endblock %} {% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('../modules/ws_customhtml/views/js/admin/customhtmlgroup_form.js') }}"></script>
{% endblock %}
@@ -5,3 +5,8 @@
{% include '@Modules/ws_customhtml/views/templates/admin/form/blocks/group_form.html.twig' %} {% include '@Modules/ws_customhtml/views/templates/admin/form/blocks/group_form.html.twig' %}
{% endblock %} {% endblock %}
{% endblock %} {% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('../modules/ws_customhtml/views/js/admin/customhtmlgroup_form.js') }}"></script>
{% endblock %}
+22 -13
View File
@@ -1,21 +1,30 @@
{if !empty($block.description)} {if !empty($block.description)}
<div <div
id="customhtml-alert-{$block.id_ws_customhtml|intval}"
class="alert alert-{$block.alert_type|escape:'html':'UTF-8'} alert-dismissible customhtml-alert" class="alert alert-{$block.alert_type|escape:'html':'UTF-8'} alert-dismissible customhtml-alert"
role="alert" role="alert"
data-timeout="{$block.timeout|intval}" data-timeout="{$block.timeout|intval}"
> >
{if $block.show_title && !empty($block.title)} <div class="row">
<strong class="customhtml-alert-title">{$block.title|escape:'html':'UTF-8'}</strong> {block name=alert_content}
{/if} <div class="col d-flex align-items-center">
<span class="customhtml-alert-text">{$block.description|escape:'html':'UTF-8'|nl2br}</span> {if $block.show_title && !empty($block.title)}
{if !empty($block.link)} <strong class="customhtml-alert-title">{$block.title|escape:'html':'UTF-8'}</strong>
<a href="{$block.link|escape:'html':'UTF-8'}" class="btn btn-{$block.alert_type|escape:'html':'UTF-8'} customhtml-alert-btn"> {/if}
{if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if} <span class="customhtml-alert-text">{$block.description|escape:'html':'UTF-8'|nl2br}</span>
</a> </div>
{/if} {/block}
<button type="button" class="close customhtml-alert-close" aria-label="{l s='Close' d='Modules.Wscustomhtml.Shop'}"> {block name=alert_actions}
<span aria-hidden="true">&times;</span> <div class="col-auto">
</button> {if !empty($block.link)}
<a href="{$block.link|escape:'html':'UTF-8'}" class="btn btn-{$block.alert_type|escape:'html':'UTF-8'} customhtml-alert-btn">
{if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if}
</a>
{/if}
<button type="button" class="close customhtml-alert-close" aria-label="{l s='Close' d='Modules.Wscustomhtml.Shop'}">
<span aria-hidden="true">&times;</span>
</button>
</div>
{/block}
</div>
</div> </div>
{/if} {/if}
+33 -18
View File
@@ -1,23 +1,38 @@
<div class="customhtml-banner row flex-column position-relative"> <div class="customhtml-banner row flex-column position-relative">
<div class="customhtml-banner-image"> {block name=banner_image}
<div class="customhtml-banner-image--gradient"></div> <div class="customhtml-banner-image">
{if !empty($block.image_url)} <div class="customhtml-banner-image--gradient"></div>
<img src="{$block.image_url|escape:'html':'UTF-8'}" alt="{$block.title|escape:'html':'UTF-8'}"> {if !empty($block.image_url)}
{else} <img src="{$block.image_url|escape:'html':'UTF-8'}" alt="{$block.title|escape:'html':'UTF-8'}">
<img {else}
src="{$urls.img_ps_url}noimageavailable.jpg" <img
alt="{$block.title|escape:'html':'UTF-8'}" src="{$urls.img_ps_url}noimageavailable.jpg"
width="100%" alt="{$block.title|escape:'html':'UTF-8'}"
class="img-fluid rounded lazyload" width="100%"
/> class="img-fluid rounded lazyload"
{/if} />
</div> {/if}
</div>
{/block}
{block name=banner_content}
<div class="customhtml-banner-content"> <div class="customhtml-banner-content">
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/_banner_content.tpl"} {if !empty($count)}
{if file_exists($customhtmlOverridePath)} <span class="customhtml-banner-count font-monospace">{$count}</span>
{include file="module:ws_customhtml/views/templates/hook/`$hookName`/_banner_content.tpl" block=$block} {/if}
{else} {if $block.show_title && !empty($block.title)}
{include file="module:ws_customhtml/views/templates/hook/_banner_content.tpl" block=$block} <h3 class="customhtml-banner-title">{$block.title|escape:'html':'UTF-8'}</h3>
{/if}
{if !empty($block.description)}
<div class="customhtml-banner-description">{$block.description|escape:'html':'UTF-8'|nl2br}</div>
{/if}
{if !empty($block.extra_description)}
<div class="customhtml-banner-extra-description">{$block.extra_description|escape:'html':'UTF-8'|nl2br}</div>
{/if}
{if !empty($block.link)}
<a href="{$block.link|escape:'html':'UTF-8'}" class="btn btn-primary customhtml-banner-link">
{if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if}
</a>
{/if} {/if}
</div> </div>
{/block}
</div> </div>
-14
View File
@@ -1,14 +0,0 @@
{if $block.show_title && !empty($block.title)}
<h3 class="customhtml-banner-title">{$block.title|escape:'html':'UTF-8'}</h3>
{/if}
{if !empty($block.description)}
<div class="customhtml-banner-description">{$block.description|escape:'html':'UTF-8'|nl2br}</div>
{/if}
{if !empty($block.extra_description)}
<div class="customhtml-banner-extra-description">{$block.extra_description|escape:'html':'UTF-8'|nl2br}</div>
{/if}
{if !empty($block.link)}
<a href="{$block.link|escape:'html':'UTF-8'}" class="btn btn-primary customhtml-banner-link">
{if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if}
</a>
{/if}
+6 -2
View File
@@ -2,8 +2,9 @@
<div class="accordion customhtml-faq-accordion" id="customhtml-faq-{$block.id_ws_customhtml|intval}"> <div class="accordion customhtml-faq-accordion" id="customhtml-faq-{$block.id_ws_customhtml|intval}">
{foreach from=$block.faqs item="faq" name="customhtmlFaqLoop"} {foreach from=$block.faqs item="faq" name="customhtmlFaqLoop"}
<div class="card"> <div class="card">
{block name=faq_question}
<div class="card-header" id="customhtml-faq-heading-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}"> <div class="card-header" id="customhtml-faq-heading-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}">
{if !empty($faq.answer)} {if !empty($faq.answer)}
<button <button
class="btn btn-link col-12 d-flex text-left{if !$smarty.foreach.customhtmlFaqLoop.first} collapsed{/if}" class="btn btn-link col-12 d-flex text-left{if !$smarty.foreach.customhtmlFaqLoop.first} collapsed{/if}"
@@ -14,7 +15,7 @@
aria-controls="customhtml-faq-collapse-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}" aria-controls="customhtml-faq-collapse-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}"
> >
{/if} {/if}
<div class="faq-question col pl-0"> <div class="faq-question col pl-0">
{$faq.question|escape:'html':'UTF-8'} {$faq.question|escape:'html':'UTF-8'}
</div> </div>
@@ -39,7 +40,9 @@
{/if} {/if}
</div> </div>
{/block}
{if !empty($faq.answer)} {if !empty($faq.answer)}
{block name=faq_answer}
<div <div
id="customhtml-faq-collapse-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}" id="customhtml-faq-collapse-{$block.id_ws_customhtml|intval}-{$faq.id_ws_customhtml_faq|intval}"
class="collapse{if $smarty.foreach.customhtmlFaqLoop.first} show{/if}" class="collapse{if $smarty.foreach.customhtmlFaqLoop.first} show{/if}"
@@ -50,6 +53,7 @@
{$faq.answer nofilter} {$faq.answer nofilter}
</div> </div>
</div> </div>
{/block}
{/if} {/if}
</div> </div>
{/foreach} {/foreach}
+1
View File
@@ -0,0 +1 @@
{extends file="module:ws_customhtml/views/templates/hook/_banner.tpl"}
+18 -13
View File
@@ -2,15 +2,16 @@
{if $block.slider_mode == 'responsive'} {if $block.slider_mode == 'responsive'}
{block name=slider_responsive} {block name=slider_responsive}
<div class="d-lg-none"> <div class="d-lg-none">
<div id="customhtml-slider-{$block.id_ws_customhtml|intval}" class="swiper customhtml-slider" data-swiper="{$block.slider_config|escape:'html':'UTF-8'}"> <div class="swiper customhtml-slider" data-swiper="{$block.slider_config|escape:'html':'UTF-8'}">
<div class="swiper-wrapper"> <div class="swiper-wrapper">
{foreach from=$block.slides item="slide" name="slides"} {foreach from=$block.slides item="slide" name="slides"}
{assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
<div class="swiper-slide"> <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)} {if file_exists($customhtmlOverridePath)}
{include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName} {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count}
{else} {else}
{include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count}
{/if} {/if}
</div> </div>
{/foreach} {/foreach}
@@ -19,12 +20,17 @@
</div> </div>
<div class="row d-none d-lg-flex customhtml-slider-grid"> <div class="row d-none d-lg-flex customhtml-slider-grid">
{foreach from=$block.slides item="slide" name="slides"} {foreach from=$block.slides item="slide" name="slides"}
{assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
{if !empty($block.slider_desktop_column_width)}
<div class="customhtml-slider-grid-item" style="flex: 0 0 {$block.slider_desktop_column_width|escape:'html':'UTF-8'}; max-width: {$block.slider_desktop_column_width|escape:'html':'UTF-8'};"> <div class="customhtml-slider-grid-item" style="flex: 0 0 {$block.slider_desktop_column_width|escape:'html':'UTF-8'}; max-width: {$block.slider_desktop_column_width|escape:'html':'UTF-8'};">
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} {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}/slide.tpl"}
{if file_exists($customhtmlOverridePath)} {if file_exists($customhtmlOverridePath)}
{include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName} {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count}
{else} {else}
{include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count}
{/if} {/if}
</div> </div>
{/foreach} {/foreach}
@@ -33,15 +39,16 @@
{/if} {/if}
{if $block.slider_mode != 'responsive'} {if $block.slider_mode != 'responsive'}
{block name=slider_always} {block name=slider_always}
<div id="customhtml-slider-{$block.id_ws_customhtml|intval}" class="swiper customhtml-slider" data-swiper="{$block.slider_config|escape:'html':'UTF-8'}"> <div class="swiper customhtml-slider" data-swiper="{$block.slider_config|escape:'html':'UTF-8'}">
<div class="swiper-wrapper"> <div class="swiper-wrapper">
{foreach from=$block.slides item="slide" name="slides"} {foreach from=$block.slides item="slide" name="slides"}
{assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
<div class="swiper-slide"> <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)} {if file_exists($customhtmlOverridePath)}
{include file="module:ws_customhtml/views/templates/hook/`$hookName`/banner.tpl" block=$slide group=$group hookName=$hookName} {include file="module:ws_customhtml/views/templates/hook/`$hookName`/slide.tpl" block=$slide group=$group hookName=$hookName count=$count}
{else} {else}
{include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} {include file="module:ws_customhtml/views/templates/hook/_slide.tpl" block=$slide count=$count}
{/if} {/if}
</div> </div>
{/foreach} {/foreach}
@@ -50,5 +57,3 @@
{/block} {/block}
{/if} {/if}
{/if} {/if}
+8 -1
View File
@@ -1,17 +1,24 @@
{if !empty($block.image_url) || ($block.show_title && !empty($block.title))} {if !empty($block.image_url) || ($block.show_title && !empty($block.title)) || !empty($block.description)}
{if !empty($block.link)} {if !empty($block.link)}
<a href="{$block.link|escape:'html':'UTF-8'}" class="customhtml-usp d-flex align-items-center"> <a href="{$block.link|escape:'html':'UTF-8'}" class="customhtml-usp d-flex align-items-center">
{else} {else}
<div class="customhtml-usp d-flex align-items-center"> <div class="customhtml-usp d-flex align-items-center">
{/if} {/if}
{block name=usp_icon}
{if !empty($block.image_url)} {if !empty($block.image_url)}
<span class="customhtml-usp-icon"> <span class="customhtml-usp-icon">
<img src="{$block.image_url|escape:'html':'UTF-8'}" alt=""> <img src="{$block.image_url|escape:'html':'UTF-8'}" alt="">
</span> </span>
{/if} {/if}
{/block}
{block name=usp_content}
{if $block.show_title && !empty($block.title)} {if $block.show_title && !empty($block.title)}
<span class="customhtml-usp-text">{$block.title|escape:'html':'UTF-8'}</span> <span class="customhtml-usp-text">{$block.title|escape:'html':'UTF-8'}</span>
{/if} {/if}
{if !empty($block.description)}
<span class="customhtml-usp-description">{$block.description|escape:'html':'UTF-8'|nl2br}</span>
{/if}
{/block}
{if !empty($block.link)} {if !empty($block.link)}
</a> </a>
{else} {else}
+4 -4
View File
@@ -1,13 +1,13 @@
{if !empty($groupList)} {if !empty($groupList)}
<div class="customhtml-container {$hookName|escape:'html':'UTF-8'}--container"> <div class="customhtml-container {$hookName|escape:'html':'UTF-8'}--container">
{foreach from=$groupList item="group"} {foreach from=$groupList item="group"}
<div class="customhtml-group customhtml-group-{$group.id_ws_customhtml_group|intval} row{if !empty($group.custom_class)} {$group.custom_class|escape:'html':'UTF-8'}{/if}"> <div class="customhtml-group row{if !empty($group.custom_class)} {$group.custom_class|escape:'html':'UTF-8'}{/if}">
{foreach from=$group.blocks item="block"} {foreach from=$group.blocks item="block" name="blocks"}
<div class="customhtml-block col{if !empty($block.custom_class)} {$block.custom_class|escape:'html':'UTF-8'}{/if}"> <div class="customhtml-block col{if !empty($group.default_block_class)} {$group.default_block_class|escape:'html':'UTF-8'}{/if}{if !empty($block.custom_class)} {$block.custom_class|escape:'html':'UTF-8'}{/if}">
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/{$block.type}.tpl"} {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/{$block.type}.tpl"}
{if file_exists($customhtmlOverridePath)} {if file_exists($customhtmlOverridePath)}
{include file="module:ws_customhtml/views/templates/hook/`$hookName`/`$block.type`.tpl" block=$block group=$group hookName=$hookName} {include file="module:ws_customhtml/views/templates/hook/`$hookName`/`$block.type`.tpl" block=$block group=$group hookName=$hookName iteration=$smarty.foreach.blocks.iteration}
{elseif $block.type == 'faq'} {elseif $block.type == 'faq'}
{if $block.show_title && !empty($block.title)} {if $block.show_title && !empty($block.title)}
<div class="customhtml-title">{$block.title|escape:'html':'UTF-8'}</div> <div class="customhtml-title">{$block.title|escape:'html':'UTF-8'}</div>
+1 -1
View File
@@ -29,7 +29,7 @@ class Ws_CustomHtml extends Module implements WidgetInterface
public function __construct() public function __construct()
{ {
$this->name = 'ws_customhtml'; $this->name = 'ws_customhtml';
$this->version = '1.17.0'; $this->version = '1.24.0';
$this->author = 'Isabelle Oving-Anno | De Websmid BV'; $this->author = 'Isabelle Oving-Anno | De Websmid BV';
$this->need_instance = 0; $this->need_instance = 0;
$this->bootstrap = true; $this->bootstrap = true;