From 3fcfc8a03b2aee25ebe20a67428a3eeb558f3888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20B=C3=A9jean?= <nicolas@bejean.eu> Date: Sat, 9 May 2020 18:53:16 +0200 Subject: [PATCH] Mise en place du champ type de template dans le widget --- Block/Widget/CategoryWidgetNew.php | 14 +++++- etc/widget.xml | 4 ++ .../widget/categorywidget/default.phtml | 49 +++++++++---------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Block/Widget/CategoryWidgetNew.php b/Block/Widget/CategoryWidgetNew.php index b1f09e4..93afc25 100755 --- a/Block/Widget/CategoryWidgetNew.php +++ b/Block/Widget/CategoryWidgetNew.php @@ -221,6 +221,18 @@ class CategoryWidgetNew extends Template implements BlockInterface return $this->getData('id'); } + /** + * Récupère le type de template du widget + */ + public function getTemplateType() + { + if ($this->getData('template_type') === '' || is_null($this->getData('template_type'))) { + return 'collection'; + } + + return $this->getData('template_type'); + } + /** * Récupère la valeur pour l'ajout d'un titre */ @@ -550,7 +562,6 @@ class CategoryWidgetNew extends Template implements BlockInterface */ public function getResizedImageWidth($imagePath) { - return $this->getWidth(); $dirPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB); $absoluteImagePath = $dirPath->getAbsolutePath($imagePath); @@ -565,7 +576,6 @@ class CategoryWidgetNew extends Template implements BlockInterface */ public function getResizedImageHeight($imagePath) { - return $this->getHeight(); $dirPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB); $absoluteImagePath = $dirPath->getAbsolutePath($imagePath); diff --git a/etc/widget.xml b/etc/widget.xml index 0f0537a..b5acfa3 100755 --- a/etc/widget.xml +++ b/etc/widget.xml @@ -40,6 +40,10 @@ <label translate="true">Widget: Category Widget --- NEW</label> <description translate="true">Category Widget Description</description> <parameters> + <parameter name="template_type" xsi:type="text" visible="true" sort_order="5"> + <label translate="true">Template type</label> + <description translate="true">Default: collection | Choice: collection, slider | Or Create Yours</description> + </parameter> <parameter name="active_title" xsi:type="select" visible="true" sort_order="10"> <label translate="true">Activate title?</label> <options> diff --git a/view/frontend/templates/widget/categorywidget/default.phtml b/view/frontend/templates/widget/categorywidget/default.phtml index c56587e..7fc6ec2 100755 --- a/view/frontend/templates/widget/categorywidget/default.phtml +++ b/view/frontend/templates/widget/categorywidget/default.phtml @@ -10,10 +10,9 @@ $activeTitleElement = $block->getActiveTitleElement(); $activeContentTop = $block->getActiveContentTop(); $activeContentBottom = $block->getActiveContentBottom(); $activeWrapper = $block->getActiveWrapper(); +$templateType = $block->getTemplateType(); $activeLink = $block->getActiveLink(); -$activeSlider = false; - if ($active) { $collection = []; $iteration = 0; @@ -50,7 +49,24 @@ if ($active) { </div> <?php endif; ?> - <?php if ($activeSlider): ?> + <?php if ($templateType === 'collection'): ?> + <div class="categorywidget-collection"> + <?php foreach ($collection as $item) : ?> + <a class="categorywidget-category-link" href="<?= /* @noEscape */ $item['url']; ?>" target="_self"> + <span class="categorywidget-category-image <?php if ($block->getImageCssClasses()): ?><?= /* @noEscape */ $block->getImageCssClasses(); ?><?php endif; ?>" + style="background-image: url('<?php echo /* @noEscape */ $item['image_path']; ?>'); width: <?= /* @noEscape */ $item['width']; ?>px; height: calc(<?= /* @noEscape */ $item['height']; ?>px + 20px); + <?php if ($block->getImageExtraCss()): ?><?= /* @noEscape */ $block->getImageExtraCss(); ?><?php endif; ?>" + > + <span class="categorywidget-category-name"> + <?= /* @noEscape */ $item['name']; ?> + </span> + </span> + </a> + <?php endforeach; ?> + </div> + <?php endif; ?> + + <?php if ($templateType === 'slider'): ?> <div class="categorywidget-slider glide hero" style="width: <?= /* @noEscape */ $block->getWidth(); ?>px; height: <?= /* @noEscape */ $block->getHeight(); ?>px;"> <div class="glide__track" data-glide-el="track"> <ul class="glide__slides"> @@ -69,31 +85,14 @@ if ($active) { </ul> </div> <?php if (count($content) > 1): ?> - <div class="glide__arrows" data-glide-el="controls"> - <button class="glide__arrow glide__arrow--prev" data-glide-dir="<">prev</button> - <button class="glide__arrow glide__arrow--next" data-glide-dir=">">next</button> - </div> + <div class="glide__arrows" data-glide-el="controls"> + <button class="glide__arrow glide__arrow--prev" data-glide-dir="<">prev</button> + <button class="glide__arrow glide__arrow--next" data-glide-dir=">">next</button> + </div> <?php endif; ?> </div> <?php endif; ?> - <?php if (!$activeSlider): ?> - <div class="categorywidget-collection"> - <?php foreach ($collection as $item) : ?> - <a class="categorywidget-category-link" href="<?= /* @noEscape */ $item['url']; ?>" target="_self"> - <span class="categorywidget-category-image <?php if ($block->getImageCssClasses()): ?><?= /* @noEscape */ $block->getImageCssClasses(); ?><?php endif; ?>" - style="background-image: url('<?php echo /* @noEscape */ $item['image_path']; ?>'); width: <?= /* @noEscape */ $item['width']; ?>px; height: calc(<?= /* @noEscape */ $item['height']; ?>px + 20px); - <?php if ($block->getImageExtraCss()): ?><?= /* @noEscape */ $block->getImageExtraCss(); ?><?php endif; ?>" - > - <span class="categorywidget-category-name"> - <?= /* @noEscape */ $item['name']; ?> - </span> - </span> - </a> - <?php endforeach; ?> - </div> - <?php endif; ?> - <?php if ($activeContentBottom): ?> <p class="categorywidget-content-bottom <?php if ($block->getWidgetContentCSS()): ?><?= /* @noEscape */ $block->getWidgetContentCSS(); ?><?php endif; ?>"><?= /* @noEscape */ $block->getWidgetContentBottom(); ?></p> <?php endif; ?> @@ -106,7 +105,7 @@ if ($active) { <?php if ($activeWrapper): ?> </div> <?php endif; ?> - <?php if (count($content) > 1 && $activeSlider): ?> + <?php if (count($content) > 1 && $templateType === 'slider'): ?> <script> require(['jquery', 'NicolasBejean_CategoryWidget/js/glide', 'domReady!'], function($, Glide){ new Glide('.glide').mount(); -- GitLab