feat(main): Add alert type; add template override support

This commit is contained in:
2026-08-13 15:31:23 +02:00
parent ce480314f3
commit 34fb95a699
18 changed files with 202 additions and 8 deletions
+8
View File
@@ -14,6 +14,14 @@ class Config
'html' => 'HTML',
'faq' => 'FAQ Accordion',
'banner' => 'Banner',
'alert' => 'Alert',
];
const ALERT_STYLES = [
'success' => 'Success',
'info' => 'Info',
'warning' => 'Warning',
'danger' => 'Danger',
];
const BANNER_IMAGE_ALLOWED_EXTENSIONS = [
@@ -27,6 +27,8 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
$block->description = (string) ($formData['description'] ?? '');
$block->extra_description = (string) ($formData['extra_description'] ?? '');
$block->link = (string) ($formData['link'] ?? '');
$block->alert_type = (string) ($formData['alert_type'] ?? 'info');
$block->timeout = (int) ($formData['timeout'] ?? 0);
$block->image = $this->saveUploadedImage($formData['image'] ?? null, '');
$block->active = (int) $formData['active'];
$block->ordering = $this->getNextOrdering($idGroup);
@@ -57,6 +59,8 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface
$block->description = (string) ($formData['description'] ?? '');
$block->extra_description = (string) ($formData['extra_description'] ?? '');
$block->link = (string) ($formData['link'] ?? '');
$block->alert_type = (string) ($formData['alert_type'] ?? 'info');
$block->timeout = (int) ($formData['timeout'] ?? 0);
$block->image = $this->saveUploadedImage($formData['image'] ?? null, $block->image);
$block->active = (int) $formData['active'];
@@ -28,6 +28,8 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface
'description' => $block->description,
'extra_description' => $block->extra_description,
'link' => $block->link,
'alert_type' => $block->alert_type,
'timeout' => (int) $block->timeout,
'faqs' => $this->loadFaqs((int) $id),
'active' => (bool) $block->active,
];
@@ -46,6 +48,8 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface
'description' => '',
'extra_description' => '',
'link' => '',
'alert_type' => 'info',
'timeout' => 0,
'faqs' => [],
'active' => true,
];
+15 -1
View File
@@ -7,6 +7,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use PrestaShop\PrestaShop\Core\Form\ConfigurableFormChoiceProviderInterface;
@@ -70,10 +71,23 @@ class CustomHtmlBlockType extends AbstractType
'prototype' => true,
'required' => false,
])
->add('alert_type', ChoiceType::class, [
'label' => $this->translator->trans('Alert style', [], 'Modules.Wscustomhtml.Admin'),
'choices' => array_flip(Config::ALERT_STYLES),
'required' => false,
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-alert'],
])
->add('timeout', IntegerType::class, [
'label' => $this->translator->trans('Auto-dismiss after (seconds)', [], 'Modules.Wscustomhtml.Admin'),
'required' => false,
'attr' => ['min' => 0, 'placeholder' => '0'],
'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'],
])
->add('description', TextareaType::class, [
'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'),
'required' => false,
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner'],
'row_attr' => ['class' => 'customhtmlblock-type-field customhtmlblock-type-banner customhtmlblock-type-alert'],
])
->add('extra_description', TextareaType::class, [
'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'),
+9 -1
View File
@@ -37,6 +37,12 @@ class CustomHtmlBlock extends ObjectModel
/** @var string */
public $image = '';
/** @var string */
public $alert_type = 'info';
/** @var int */
public $timeout = 0;
/** @var int */
public $active = 1;
@@ -65,6 +71,8 @@ class CustomHtmlBlock extends ObjectModel
'extra_description' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 1024],
'link' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 512],
'image' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 255],
'alert_type' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => false, 'size' => 16],
'timeout' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => false],
'active' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'show_title' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool'],
'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'],
@@ -97,7 +105,7 @@ class CustomHtmlBlock extends ObjectModel
$result = Db::getInstance()->executeS(
'SELECT `id_ws_customhtml`, `id_ws_customhtml_group`, `title`, `type`, `content`, `custom_class`,
`description`, `extra_description`, `link`, `image`, `active`, `show_title`, `ordering`
`description`, `extra_description`, `link`, `image`, `alert_type`, `timeout`, `active`, `show_title`, `ordering`
FROM `' . _DB_PREFIX_ . 'ws_customhtml`
WHERE `id_ws_customhtml_group` IN (' . implode(',', $groupIds) . ')
AND `active` = 1
+5
View File
@@ -15,6 +15,11 @@ trait DisplayHooks
'ws_customhtml_front',
'/modules/' . $this->name . '/views/css/front/customhtml.css'
);
$this->context->controller->registerJavascript(
'ws_customhtml_front',
'/modules/' . $this->name . '/views/js/front/customhtml.js'
);
}
public function renderWidget($hookName = null, array $configuration = [])