From 547127f1d72e8426c7224262aff40392d7c1b0be Mon Sep 17 00:00:00 2001 From: Nicolas <nicolas@bejean.eu> Date: Sun, 7 Oct 2018 15:02:01 +0200 Subject: [PATCH] =?UTF-8?q?Corrections=20:=20Possibilit=C3=A9=20de=20chois?= =?UTF-8?q?ir=20entre=202=20templates=20sans=20intervenir=20dans=20le=20co?= =?UTF-8?q?de?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Block/Widget/CategoryWidget.php | 13 +--- etc/widget.xml | 2 +- .../templates/widget/category_widget.phtml | 76 ++++++------------- .../category_widget_img_background.phtml | 16 +++- 4 files changed, 45 insertions(+), 62 deletions(-) diff --git a/Block/Widget/CategoryWidget.php b/Block/Widget/CategoryWidget.php index 8e3f808..00e76de 100755 --- a/Block/Widget/CategoryWidget.php +++ b/Block/Widget/CategoryWidget.php @@ -3,9 +3,6 @@ namespace NicolasBejean\CategoryWidget\Block\Widget; class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface { - protected $_template = "widget/category_widget.phtml"; - /*protected $_template;*/ - /** * Default value for products count that will be shown */ @@ -65,8 +62,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements */ public function getWidgetTitle() { - $widgetTitle = $this->getData('widget_title'); - return $widgetTitle; + return $this->getData('widget_title'); } /** @@ -74,8 +70,7 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements */ public function getWidgetContent() { - $widgetContent = $this->getData('widget_content'); - return $widgetContent; + return $this->getData('widget_content'); } /** @@ -97,8 +92,8 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements /** * Récupère le template du widget */ - public function getModel() + public function getTemplate() { - return $this->getData('model'); + return $this->getData('template'); } } \ No newline at end of file diff --git a/etc/widget.xml b/etc/widget.xml index f089c06..c4203ac 100755 --- a/etc/widget.xml +++ b/etc/widget.xml @@ -15,7 +15,7 @@ <label translate="true">category_selection</label> <description translate="true">category_selection_description</description> </parameter> - <parameter name="model" xsi:type="select" visible="true"> + <parameter name="template" xsi:type="select" required="true" visible="true"> <label translate="true">template</label> <options> <option name="default" value="widget/category_widget.phtml" selected="true"> diff --git a/view/frontend/templates/widget/category_widget.phtml b/view/frontend/templates/widget/category_widget.phtml index a9d193b..e101b02 100755 --- a/view/frontend/templates/widget/category_widget.phtml +++ b/view/frontend/templates/widget/category_widget.phtml @@ -4,60 +4,34 @@ ?> <div class="widget block block-static-block category-widget"> <div class="block-content"> - <?php if($this->getModel() == "widget/category_widget.phtml") { ?> - <?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?> - <div class="content-heading"> - <?php if($this->getWidgetTitle() != null): ?> - <h2 class="title"> - <?php echo $this->getWidgetTitle(); ?> - </h2> - <?php endif; ?> - <?php if($this->getWidgetContent() != null): ?> - <p class="content"> - <?php echo $this->getWidgetContent(); ?> - </p> - <?php endif; ?> - </div> + <?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?> + <div class="content-heading"> + <?php if($this->getWidgetTitle() != null): ?> + <h2 class="title"> + <?php echo $this->getWidgetTitle(); ?> + </h2> <?php endif; ?> - <?php if($categories != null): ?> - <div class="categories"> - <?php - foreach($categories as $category): - $cat = $this->getCategoryModel($category->getId()); - - if($cat->getImageUrl() != null): ?> - <a class="category" href="<?php echo $cat->getUrl(); ?>"> - <img src="<?php echo $cat->getImageUrl(); ?>" class="img-responsive category_image" alt="<?php echo $cat->getName(); ?>" /> - <span><?php echo $cat->getName(); ?></span> - </a> - <?php endif; ?> - <?php endforeach; ?> - </div> + <?php if($this->getWidgetContent() != null): ?> + <p class="content"> + <?php echo $this->getWidgetContent(); ?> + </p> <?php endif; ?> + </div> + <?php endif; ?> + <?php if($categories != null): ?> + <div class="categories"> <?php - /* - * TODO : Pouvoir sélectionner un template de rendu sans intervenir dans le code - */ - ?> - <?php } elseif ($this->getModel("widget/category_widget_img_background.phtml")) { ?> - <?php if($categories != null): ?> - <div class="categories"> - <?php - foreach($categories as $category): - $cat = $this->getCategoryModel($category->getId()); + foreach($categories as $category): + $cat = $this->getCategoryModel($category->getId()); - if($cat->getImageUrl() != null): ?> - <a class="category img-background" href="<?php echo $cat->getUrl(); ?>" style="background-image: url(<?php echo $cat->getImageUrl(); ?>)"> - <span><?php echo $cat->getName(); ?></span> - </a> - <?php endif; ?> - <?php endforeach; ?> - </div> - <?php endif; ?> - <?php } else { ?> - <p class="message global demo"> - <?php echo __('no_model'); ?> - </p> - <?php } ?> + if($cat->getImageUrl() != null): ?> + <a class="category" href="<?php echo $cat->getUrl(); ?>"> + <img src="<?php echo $cat->getImageUrl(); ?>" class="img-responsive category_image" alt="<?php echo $cat->getName(); ?>" /> + <span><?php echo $cat->getName(); ?></span> + </a> + <?php endif; ?> + <?php endforeach; ?> + </div> + <?php endif; ?> </div> </div> diff --git a/view/frontend/templates/widget/category_widget_img_background.phtml b/view/frontend/templates/widget/category_widget_img_background.phtml index a9e72cf..cf1360a 100755 --- a/view/frontend/templates/widget/category_widget_img_background.phtml +++ b/view/frontend/templates/widget/category_widget_img_background.phtml @@ -4,6 +4,20 @@ ?> <div class="widget block block-static-block category-widget"> <div class="block-content"> + <?php if($this->getWidgetTitle() != null || $this->getWidgetContent() != null): ?> + <div class="content-heading"> + <?php if($this->getWidgetTitle() != null): ?> + <h2 class="title"> + <?php echo $this->getWidgetTitle(); ?> + </h2> + <?php endif; ?> + <?php if($this->getWidgetContent() != null): ?> + <p class="content"> + <?php echo $this->getWidgetContent(); ?> + </p> + <?php endif; ?> + </div> + <?php endif; ?> <?php if($categories != null): ?> <div class="categories"> <?php @@ -12,7 +26,7 @@ $image = $cat->getImageUrl(); if($image != null): ?> - <a class="category" href="<?php echo $cat->getUrl(); ?>" style="background-image: url(\"<?php echo $image; ?>\")"> + <a class="category" href="<?php echo $cat->getUrl(); ?>" style="background-image: url('<?php echo $image; ?>')"> <span><?php echo $cat->getName(); ?></span> </a> <?php endif; ?> -- GitLab