diff --git a/src/Config/Config.php b/src/Config/Config.php index 43c8fdf..459cb9d 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -23,11 +23,9 @@ class Config const SLIDER_DEFAULT_SLIDES_PER_VIEW_TABLET = 2; - const SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP = 3; - const SLIDER_MODES = [ 'always' => 'Always show as a slider', - 'responsive' => 'Slider on mobile/tablet, static grid on desktop', + 'responsive' => 'Mobile only', ]; const SLIDER_DEFAULT_MODE = 'always'; diff --git a/src/Controller/CustomHtmlBlockController.php b/src/Controller/CustomHtmlBlockController.php index f7e8750..c30dc21 100644 --- a/src/Controller/CustomHtmlBlockController.php +++ b/src/Controller/CustomHtmlBlockController.php @@ -21,8 +21,11 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController { public function indexAction(Request $request, CustomHtmlBlockFilters $filters): Response { + $idGroup = null; + 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); } @@ -31,7 +34,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController return $this->render('@Modules/ws_customhtml/views/templates/admin/grid/customhtmlblock.html.twig', [ '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'); $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')) { - $form->get('id_ws_customhtml_group')->setData((int) $request->query->get('idGroup')); + if ($request->isMethod('GET') && null !== $idGroup) { + $form->get('id_ws_customhtml_group')->setData($idGroup); } $form->handleRequest($request); @@ -64,7 +69,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController if (null !== $handlerResult->getIdentifiableObjectId()) { $this->addFlash('success', $this->trans('Successful creation.', 'Admin.Notifications.Success')); - return $this->redirectToRoute('customhtmlblock_index'); + return $this->redirectToRoute('customhtmlblock_index', $redirectParams); } } catch (Exception $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', [ 'customHtmlBlockForm' => $form->createView(), + 'idGroup' => $idGroup, ]); } @@ -81,6 +87,8 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController $formHandler = $this->get('websmid.customhtml.form.customhtmlblock_form_handler'); $form = $formBuilder->getFormFor($idCustomHtmlBlock); + $idGroup = $request->query->has('idGroup') ? (int) $request->query->get('idGroup') : null; + $redirectParams = null !== $idGroup ? ['idGroup' => $idGroup] : []; try { $form->handleRequest($request); @@ -89,7 +97,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController if ($handlerResult->isSubmitted() && $handlerResult->isValid()) { $this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success')); - return $this->redirectToRoute('customhtmlblock_index'); + return $this->redirectToRoute('customhtmlblock_index', $redirectParams); } } catch (Exception $e) { $this->addFlash('error', $this->getErrorMessageForException($e, [])); @@ -102,24 +110,28 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController 'customHtmlBlockForm' => $form->createView(), 'idCustomHtmlBlock' => $idCustomHtmlBlock, 'currentImageUrl' => $currentImageUrl, + 'idGroup' => $idGroup, ]); } 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); if (!Validate::isLoadedObject($block)) { $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); $block->delete(); $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 @@ -144,7 +156,7 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController return $this->redirectToRoute('customhtmlblock_index', ['idGroup' => $idGroup]); } - private function getToolbarButtons(?string $securitySubject): array + private function getToolbarButtons(?string $securitySubject, ?int $idGroup = null): array { $toolbarButtons = []; @@ -152,8 +164,10 @@ class CustomHtmlBlockController extends FrameworkBundleAdminController return $toolbarButtons; } + $routeParams = null !== $idGroup ? ['idGroup' => $idGroup] : []; + $toolbarButtons['customhtmlblock_create'] = [ - 'href' => $this->generateUrl('customhtmlblock_create'), + 'href' => $this->generateUrl('customhtmlblock_create', $routeParams), 'desc' => $this->trans('New block', 'Admin.Actions'), 'icon' => 'add_circle_outline', 'class' => 'btn-primary', diff --git a/src/Form/ChoiceProvider/CustomHtmlGroupChoiceProvider.php b/src/Form/ChoiceProvider/CustomHtmlGroupChoiceProvider.php index 02627ed..1f12272 100644 --- a/src/Form/ChoiceProvider/CustomHtmlGroupChoiceProvider.php +++ b/src/Form/ChoiceProvider/CustomHtmlGroupChoiceProvider.php @@ -14,22 +14,9 @@ final class CustomHtmlGroupChoiceProvider implements { 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 = []; - foreach ($groups as $group) { - $label = $group['title']; - - if ($titleCounts[$label] > 1) { - $label .= ' (#' . $group['id_ws_customhtml_group'] . ')'; - } - + foreach ($this->getGroupsWithLabels() as $label => $group) { $choices[$label] = (int) $group['id_ws_customhtml_group']; } @@ -38,6 +25,38 @@ final class CustomHtmlGroupChoiceProvider implements 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 + { + $groups = Db::getInstance()->executeS( + 'SELECT `id_ws_customhtml_group`, `title`, `default_block_class` + FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` + ORDER BY `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; } } diff --git a/src/Form/DataHandler/CustomHtmlBlockDataHandler.php b/src/Form/DataHandler/CustomHtmlBlockDataHandler.php index f22dece..9fbbcfd 100644 --- a/src/Form/DataHandler/CustomHtmlBlockDataHandler.php +++ b/src/Form/DataHandler/CustomHtmlBlockDataHandler.php @@ -34,7 +34,7 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface $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_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->image = $this->saveUploadedImage($formData['image'] ?? null, ''); $block->active = (int) $formData['active']; @@ -73,7 +73,7 @@ final class CustomHtmlBlockDataHandler implements FormDataHandlerInterface $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_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->image = $this->saveUploadedImage($formData['image'] ?? null, $block->image); $block->active = (int) $formData['active']; diff --git a/src/Form/DataHandler/CustomHtmlGroupDataHandler.php b/src/Form/DataHandler/CustomHtmlGroupDataHandler.php index a21cd4f..48adb87 100644 --- a/src/Form/DataHandler/CustomHtmlGroupDataHandler.php +++ b/src/Form/DataHandler/CustomHtmlGroupDataHandler.php @@ -18,6 +18,7 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface $group->title = (string) $formData['title']; $group->hook_name = (string) $formData['hook_name']; $group->custom_class = (string) ($formData['custom_class'] ?? ''); + $group->default_block_class = (string) ($formData['default_block_class'] ?? ''); $group->active = (int) $formData['active']; $group->ordering = $this->getNextOrdering(); @@ -50,6 +51,7 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface $group->title = (string) $formData['title']; $group->hook_name = (string) $formData['hook_name']; $group->custom_class = (string) ($formData['custom_class'] ?? ''); + $group->default_block_class = (string) ($formData['default_block_class'] ?? ''); $group->active = (int) $formData['active']; if (!$group->update()) { diff --git a/src/Form/DataProvider/CustomHtmlBlockDataProvider.php b/src/Form/DataProvider/CustomHtmlBlockDataProvider.php index f9f4141..493c2d1 100644 --- a/src/Form/DataProvider/CustomHtmlBlockDataProvider.php +++ b/src/Form/DataProvider/CustomHtmlBlockDataProvider.php @@ -36,7 +36,7 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface 'slider_mode' => $block->slider_mode, 'slides_per_view_mobile' => (float) $block->slides_per_view_mobile, '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, 'faqs' => $this->loadFaqs((int) $id), 'slides' => $this->loadSlides((int) $id), @@ -63,7 +63,7 @@ final class CustomHtmlBlockDataProvider implements FormDataProviderInterface 'slider_mode' => Config::SLIDER_DEFAULT_MODE, '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_desktop' => Config::SLIDER_DEFAULT_SLIDES_PER_VIEW_DESKTOP, + 'slides_per_view_desktop' => null, 'autoplay_delay' => 0, 'faqs' => [], 'slides' => [], diff --git a/src/Form/DataProvider/CustomHtmlGroupDataProvider.php b/src/Form/DataProvider/CustomHtmlGroupDataProvider.php index 2739ad5..c0eea0f 100644 --- a/src/Form/DataProvider/CustomHtmlGroupDataProvider.php +++ b/src/Form/DataProvider/CustomHtmlGroupDataProvider.php @@ -17,20 +17,22 @@ final class CustomHtmlGroupDataProvider implements FormDataProviderInterface } return [ - 'title' => $group->title, - 'hook_name' => $group->hook_name, - 'custom_class' => $group->custom_class, - 'active' => (bool) $group->active, + 'title' => $group->title, + 'hook_name' => $group->hook_name, + 'custom_class' => $group->custom_class, + 'default_block_class' => $group->default_block_class, + 'active' => (bool) $group->active, ]; } public function getDefaultData() { return [ - 'title' => '', - 'hook_name' => '', - 'custom_class' => '', - 'active' => true, + 'title' => '', + 'hook_name' => '', + 'custom_class' => '', + 'default_block_class' => '', + 'active' => true, ]; } } diff --git a/src/Form/Type/CustomHtmlBlockType.php b/src/Form/Type/CustomHtmlBlockType.php index 754d929..bd657f2 100644 --- a/src/Form/Type/CustomHtmlBlockType.php +++ b/src/Form/Type/CustomHtmlBlockType.php @@ -33,9 +33,10 @@ class CustomHtmlBlockType extends AbstractType { $formBuilder ->add('id_ws_customhtml_group', ChoiceType::class, [ - 'label' => $this->translator->trans('Group', [], 'Modules.Wscustomhtml.Admin'), - 'choices' => $this->groupChoiceProvider->getChoices(), - 'required' => true, + 'label' => $this->translator->trans('Group', [], 'Modules.Wscustomhtml.Admin'), + 'choices' => $this->groupChoiceProvider->getChoices(), + 'choice_attr' => $this->groupChoiceProvider->getChoicesAttributes(), + 'required' => true, ]) ->add('type', ChoiceType::class, [ 'label' => $this->translator->trans('Block type', [], 'Modules.Wscustomhtml.Admin'), @@ -83,6 +84,7 @@ class CustomHtmlBlockType extends AbstractType 'label' => $this->translator->trans('Slider mode', [], 'Modules.Wscustomhtml.Admin'), 'choices' => array_flip(Config::SLIDER_MODES), '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'], ]) ->add('slides_per_view_mobile', NumberType::class, [ @@ -103,8 +105,8 @@ class CustomHtmlBlockType extends AbstractType 'label' => $this->translator->trans('Slides visible on desktop', [], 'Modules.Wscustomhtml.Admin'), 'required' => false, 'scale' => 2, - 'attr' => ['min' => 0, 'step' => '0.05'], - 'help' => $this->translator->trans('In "static grid on desktop" mode this is rounded to the nearest whole number of columns.', [], 'Modules.Wscustomhtml.Admin'), + 'attr' => ['min' => 0, 'step' => '0.05', 'placeholder' => $this->translator->trans('Auto', [], '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'], ]) ->add('autoplay_delay', IntegerType::class, [ @@ -130,7 +132,7 @@ class CustomHtmlBlockType extends AbstractType ->add('description', TextareaType::class, [ 'label' => $this->translator->trans('Description', [], 'Modules.Wscustomhtml.Admin'), '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, [ 'label' => $this->translator->trans('Extra description', [], 'Modules.Wscustomhtml.Admin'), diff --git a/src/Form/Type/CustomHtmlGroupType.php b/src/Form/Type/CustomHtmlGroupType.php index 121132c..08ee1a3 100644 --- a/src/Form/Type/CustomHtmlGroupType.php +++ b/src/Form/Type/CustomHtmlGroupType.php @@ -29,10 +29,16 @@ class CustomHtmlGroupType extends AbstractType 'required' => true, ]) ->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, '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, [ 'label' => $this->translator->trans('Active', [], 'Modules.Wscustomhtml.Admin'), 'required' => false, diff --git a/src/Grid/Definition/Factory/CustomHtmlBlockGridDefinitionFactory.php b/src/Grid/Definition/Factory/CustomHtmlBlockGridDefinitionFactory.php index 0d0be42..7d01331 100644 --- a/src/Grid/Definition/Factory/CustomHtmlBlockGridDefinitionFactory.php +++ b/src/Grid/Definition/Factory/CustomHtmlBlockGridDefinitionFactory.php @@ -170,10 +170,17 @@ final class CustomHtmlBlockGridDefinitionFactory extends AbstractGridDefinitionF 'route_param_field' => 'id_ws_customhtml', 'use_inline_display' => true, 'clickable_row' => true, + 'extra_route_params' => ['idGroup' => 'id_ws_customhtml_group'], ]) ) ->add( - $this->buildDeleteAction('customhtmlblock_delete', 'idCustomHtmlBlock', 'id_ws_customhtml') + $this->buildDeleteAction( + 'customhtmlblock_delete', + 'idCustomHtmlBlock', + 'id_ws_customhtml', + 'POST', + ['idGroup' => 'id_ws_customhtml_group'] + ) ); } } diff --git a/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php b/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php index 2e96696..3a47da8 100644 --- a/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php +++ b/src/Grid/Definition/Factory/CustomHtmlGroupGridDefinitionFactory.php @@ -72,11 +72,6 @@ final class CustomHtmlGroupGridDefinitionFactory extends AbstractGridDefinitionF ->setName($this->trans('Hook', [], 'Modules.Wscustomhtml.Admin')) ->setOptions(['field' => 'hook_name']) ) - ->add( - (new DataColumn('custom_class')) - ->setName($this->trans('Custom classes', [], 'Modules.Wscustomhtml.Admin')) - ->setOptions(['field' => 'custom_class']) - ) ->add( (new DataColumn('blocks_count')) ->setName($this->trans('Blocks', [], 'Modules.Wscustomhtml.Admin')) diff --git a/src/Model/CustomHtmlGroup.php b/src/Model/CustomHtmlGroup.php index fd1377a..831d8ed 100644 --- a/src/Model/CustomHtmlGroup.php +++ b/src/Model/CustomHtmlGroup.php @@ -19,6 +19,9 @@ class CustomHtmlGroup extends ObjectModel /** @var string */ public $custom_class = ''; + /** @var string */ + public $default_block_class = ''; + /** @var int */ public $active = 1; @@ -38,6 +41,7 @@ class CustomHtmlGroup extends ObjectModel 'hook_name' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 64], 'title' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 256], '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'], 'ordering' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], @@ -48,7 +52,7 @@ class CustomHtmlGroup extends ObjectModel public static function getActiveByHookName(string $hookName): array { $result = Db::getInstance()->executeS( - 'SELECT `id_ws_customhtml_group`, `title`, `active`, `custom_class`, `ordering` + 'SELECT `id_ws_customhtml_group`, `title`, `active`, `custom_class`, `default_block_class`, `ordering` FROM `' . _DB_PREFIX_ . 'ws_customhtml_group` WHERE `hook_name` = \'' . pSQL($hookName) . '\' AND `active` = 1 diff --git a/src/Module/DisplayHooks.php b/src/Module/DisplayHooks.php index bf5d2b4..0a82a85 100644 --- a/src/Module/DisplayHooks.php +++ b/src/Module/DisplayHooks.php @@ -152,8 +152,11 @@ trait DisplayHooks } else { $config['breakpoints'] = [ 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) { @@ -167,8 +170,12 @@ trait DisplayHooks 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'])); return round(100 / $columns, 4) . '%'; diff --git a/src/Module/Install.php b/src/Module/Install.php index 42bd874..736e8c6 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -51,6 +51,7 @@ trait Install `hook_name` VARCHAR(64) NOT NULL, `title` VARCHAR(256) 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, `ordering` INT(11) NOT NULL DEFAULT 0, `date_add` DATETIME NOT NULL, diff --git a/theme-overrides/displayHomeUsps1/banner.tpl b/theme-overrides/displayHomeUsps1/banner.tpl new file mode 100644 index 0000000..01a5f80 --- /dev/null +++ b/theme-overrides/displayHomeUsps1/banner.tpl @@ -0,0 +1,10 @@ +{if !empty($block.link)}{/if} +

+ {$block.title|escape:'html':'UTF-8'} +

+ {if !empty($block.description)} +

+ {$block.description|escape:'html':'UTF-8'|nl2br} +

+ {/if} +{if !empty($block.link)}
{/if} diff --git a/theme-overrides/displayHomeUsps2/usp.tpl b/theme-overrides/displayHomeUsps2/usp.tpl new file mode 100644 index 0000000..cfae01a --- /dev/null +++ b/theme-overrides/displayHomeUsps2/usp.tpl @@ -0,0 +1,11 @@ +{if !empty($block.link)}{/if} + /{$iteration|string_format:"%02d"} +

+ {$block.title|escape:'html':'UTF-8'} +

+ {if !empty($block.description)} +

+ {$block.description|escape:'html':'UTF-8'|nl2br} +

+ {/if} +{if !empty($block.link)}
{/if} diff --git a/upgrade/upgrade-1.19.0.php b/upgrade/upgrade-1.19.0.php new file mode 100644 index 0000000..b70737a --- /dev/null +++ b/upgrade/upgrade-1.19.0.php @@ -0,0 +1,21 @@ +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`' + ); +} diff --git a/views/css/front/customhtml.css b/views/css/front/customhtml.css index 2a22a43..b78a53a 100644 --- a/views/css/front/customhtml.css +++ b/views/css/front/customhtml.css @@ -7,6 +7,7 @@ padding: 2rem; bottom: 0px; position: absolute; + z-index: 2; } .customhtml-banner-title { @@ -18,13 +19,16 @@ margin-bottom: 1rem; } -/* .customhtml-banner-image--gradient { - width: 100%; - height: 100%; +.customhtml-banner-image { + position: relative; +} + +.customhtml-banner-image--gradient { position: absolute; - background: transparent linear-gradient(180deg, #27272777 0%, #272727 100%) - 0% 0% no-repeat padding-box; -} */ + inset: 0; + pointer-events: none; + z-index: 1; +} /* Alert */ .customhtml-alert { max-height: 500px; diff --git a/views/js/admin/customhtmlblock_form.js b/views/js/admin/customhtmlblock_form.js index f2ea562..6a4d428 100644 --- a/views/js/admin/customhtmlblock_form.js +++ b/views/js/admin/customhtmlblock_form.js @@ -18,6 +18,20 @@ $(document).ready(function () { $('#custom_html_block_type').on('change', 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) { var container = $(containerSelector); var removeLabel = container.data('removeLabel'); diff --git a/views/templates/admin/form/blocks/block_form.html.twig b/views/templates/admin/form/blocks/block_form.html.twig index aeb08e4..490d092 100644 --- a/views/templates/admin/form/blocks/block_form.html.twig +++ b/views/templates/admin/form/blocks/block_form.html.twig @@ -114,12 +114,17 @@ {{ form_row(customHtmlBlockForm.link_text) }} +

{{ form_row(customHtmlBlockForm.custom_class) }} {{ form_row(customHtmlBlockForm.active) }} {{ form_rest(customHtmlBlockForm) }} {/if} diff --git a/views/templates/hook/_banner.tpl b/views/templates/hook/_banner.tpl index c078d13..2ed0be9 100644 --- a/views/templates/hook/_banner.tpl +++ b/views/templates/hook/_banner.tpl @@ -1,23 +1,38 @@
-
-
- {if !empty($block.image_url)} - {$block.title|escape:'html':'UTF-8'} - {else} - {$block.title|escape:'html':'UTF-8'} - {/if} -
+ {block name=banner_image} +
+
+ {if !empty($block.image_url)} + {$block.title|escape:'html':'UTF-8'} + {else} + {$block.title|escape:'html':'UTF-8'} + {/if} +
+ {/block} + {block name=banner_content}
- {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/_banner_content.tpl"} - {if file_exists($customhtmlOverridePath)} - {include file="module:ws_customhtml/views/templates/hook/`$hookName`/_banner_content.tpl" block=$block} - {else} - {include file="module:ws_customhtml/views/templates/hook/_banner_content.tpl" block=$block} + {if !empty($count)} + {$count} + {/if} + {if $block.show_title && !empty($block.title)} +

{$block.title|escape:'html':'UTF-8'}

+ {/if} + {if !empty($block.description)} +
{$block.description|escape:'html':'UTF-8'|nl2br}
+ {/if} + {if !empty($block.extra_description)} +
{$block.extra_description|escape:'html':'UTF-8'|nl2br}
+ {/if} + {if !empty($block.link)} + + {if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if} + {/if}
+ {/block}
\ No newline at end of file diff --git a/views/templates/hook/_banner_content.tpl b/views/templates/hook/_banner_content.tpl deleted file mode 100644 index 7562439..0000000 --- a/views/templates/hook/_banner_content.tpl +++ /dev/null @@ -1,14 +0,0 @@ -{if $block.show_title && !empty($block.title)} -

{$block.title|escape:'html':'UTF-8'}

-{/if} -{if !empty($block.description)} -
{$block.description|escape:'html':'UTF-8'|nl2br}
-{/if} -{if !empty($block.extra_description)} -
{$block.extra_description|escape:'html':'UTF-8'|nl2br}
-{/if} -{if !empty($block.link)} - - {if !empty($block.link_text)}{$block.link_text|escape:'html':'UTF-8'}{else}{l s='Learn more' d='Modules.Wscustomhtml.Shop'}{/if} - -{/if} diff --git a/views/templates/hook/_faq_accordion.tpl b/views/templates/hook/_faq_accordion.tpl index 572c83a..e2fa71a 100644 --- a/views/templates/hook/_faq_accordion.tpl +++ b/views/templates/hook/_faq_accordion.tpl @@ -2,8 +2,9 @@
{foreach from=$block.faqs item="faq" name="customhtmlFaqLoop"}
+ {block name=faq_question}
- + {if !empty($faq.answer)}
+ {/block} {if !empty($faq.answer)} + {block name=faq_answer}
+ {/block} {/if}
{/foreach} diff --git a/views/templates/hook/_slider.tpl b/views/templates/hook/_slider.tpl index 44d7ccd..50fbb53 100644 --- a/views/templates/hook/_slider.tpl +++ b/views/templates/hook/_slider.tpl @@ -2,15 +2,16 @@ {if $block.slider_mode == 'responsive'} {block name=slider_responsive}
-
+
{foreach from=$block.slides item="slide" name="slides"} + {assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} {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`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} + {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} {/if}
{/foreach} @@ -19,12 +20,17 @@
{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)}
+ {else} +
+ {/if} {assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} {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`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} + {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} {/if}
{/foreach} @@ -33,15 +39,16 @@ {/if} {if $block.slider_mode != 'responsive'} {block name=slider_always} -
+
{foreach from=$block.slides item="slide" name="slides"} + {assign var="count" value=$smarty.foreach.slides.iteration|string_format:"%02d"}
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/banner.tpl"} {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`/banner.tpl" block=$slide group=$group hookName=$hookName count=$count} {else} - {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide} + {include file="module:ws_customhtml/views/templates/hook/_banner.tpl" block=$slide count=$count} {/if}
{/foreach} @@ -50,5 +57,3 @@ {/block} {/if} {/if} - - diff --git a/views/templates/hook/_usp.tpl b/views/templates/hook/_usp.tpl index b1a7500..23474a7 100644 --- a/views/templates/hook/_usp.tpl +++ b/views/templates/hook/_usp.tpl @@ -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)} {else}
{/if} + {block name=usp_icon} {if !empty($block.image_url)} {/if} + {/block} + {block name=usp_content} {if $block.show_title && !empty($block.title)} {$block.title|escape:'html':'UTF-8'} {/if} + {if !empty($block.description)} + {$block.description|escape:'html':'UTF-8'|nl2br} + {/if} + {/block} {if !empty($block.link)} {else} diff --git a/views/templates/hook/customhtml_block.tpl b/views/templates/hook/customhtml_block.tpl index 0e525e2..720cc0f 100644 --- a/views/templates/hook/customhtml_block.tpl +++ b/views/templates/hook/customhtml_block.tpl @@ -1,13 +1,13 @@ {if !empty($groupList)}
{foreach from=$groupList item="group"} -
- {foreach from=$group.blocks item="block"} -
+
+ {foreach from=$group.blocks item="block" name="blocks"} +
{assign var="customhtmlOverridePath" value="{$smarty.const._PS_THEME_DIR_}modules/ws_customhtml/views/templates/hook/{$hookName}/{$block.type}.tpl"} {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'} {if $block.show_title && !empty($block.title)}
{$block.title|escape:'html':'UTF-8'}
diff --git a/ws_customhtml.php b/ws_customhtml.php index ee51d2e..a7c8a86 100644 --- a/ws_customhtml.php +++ b/ws_customhtml.php @@ -29,7 +29,7 @@ class Ws_CustomHtml extends Module implements WidgetInterface public function __construct() { $this->name = 'ws_customhtml'; - $this->version = '1.17.0'; + $this->version = '1.19.0'; $this->author = 'Isabelle Oving-Anno | De Websmid BV'; $this->need_instance = 0; $this->bootstrap = true;