From 1a6126d5bbe12601ddac575327ef8a652f414999 Mon Sep 17 00:00:00 2001
From: Nicolas BEJEAN <nicolas.bejean@api-and-you.com>
Date: Tue, 22 Jan 2019 16:33:11 +0100
Subject: [PATCH] Corrections de l'affichage du template

---
 Block/Widget/CategoryWidget.php      | 10 ++++++++--
 Model/Config/Source/CategoryList.php | 23 +++++++----------------
 etc/widget.xml                       | 26 +++++++++++++-------------
 3 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/Block/Widget/CategoryWidget.php b/Block/Widget/CategoryWidget.php
index 49d7c3a..e7cca13 100755
--- a/Block/Widget/CategoryWidget.php
+++ b/Block/Widget/CategoryWidget.php
@@ -1,7 +1,10 @@
 <?php
 namespace NicolasBejean\CategoryWidget\Block\Widget;
 
-class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
+use Magento\Framework\View\Element\Template;
+use Magento\Widget\Block\BlockInterface;
+
+class CategoryWidget extends Template implements BlockInterface
 {
     /**
      * Category helper
@@ -120,7 +123,10 @@ class CategoryWidget extends \Magento\Framework\View\Element\Template implements
      */
     public function getTemplate()
     {
-        return $this->getData('template');
+        if ($this->hasData('template')) {
+            $this->setTemplate($this->getData('template'));
+        }
+        return $this->_template;
     }
 
     /**
diff --git a/Model/Config/Source/CategoryList.php b/Model/Config/Source/CategoryList.php
index be758b4..5e6a58a 100755
--- a/Model/Config/Source/CategoryList.php
+++ b/Model/Config/Source/CategoryList.php
@@ -18,7 +18,7 @@ class CategoryList implements ArrayInterface
 
     public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
     {
-        return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
+        return $this->_categoryHelper->getStoreCategories($sorted, $asCollection, $toLoad);
     }
 
     /*
@@ -27,19 +27,15 @@ class CategoryList implements ArrayInterface
      */
     public function toOptionArray()
     {
-
-
         $arr = $this->toArray();
         $ret = [];
 
-        foreach ($arr as $key => $value)
-        {
-
+        foreach ($arr as $key => $value) :
             $ret[] = [
                 'value' => $key,
                 'label' => $value
             ];
-        }
+        endforeach;
 
         return $ret;
     }
@@ -50,19 +46,14 @@ class CategoryList implements ArrayInterface
      */
     public function toArray()
     {
-        /*
-         * Le paramètre asCollection permet à true d'afficher le second niveau des catégories
-         */
-
+        /* Le paramètre asCollection permet à true d'afficher le second niveau des catégories */
         $categories = $this->getStoreCategories(false,true,true);
-
         $categoryList = array();
 
-        foreach ($categories as $category){
-
+        foreach ($categories as $category) :
             $categoryList[$category->getEntityId()] = __($category->getName());
-        }
+        endforeach;
 
         return $categoryList;
     }
-}
\ No newline at end of file
+}
diff --git a/etc/widget.xml b/etc/widget.xml
index f27e6e0..1459aa5 100755
--- a/etc/widget.xml
+++ b/etc/widget.xml
@@ -2,35 +2,35 @@
 <widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
 	<widget id="nicolasbejean_categorywidget" class="NicolasBejean\CategoryWidget\Block\Widget\CategoryWidget">
-		<label translate="true">widget_label</label>
-		<description translate="true">widget_description</description>
+		<label>widget_label</label>
+		<description>widget_description</description>
 		<parameters>
             <parameter name="widget_title" xsi:type="text" visible="true" sort_order="1">
-                <label translate="true">widget_title</label>
+                <label>widget_title</label>
             </parameter>
             <parameter name="widget_content" xsi:type="text" visible="true" sort_order="2">
-                <label translate="true">widget_content</label>
+                <label>widget_content</label>
             </parameter>
 			<parameter name="category_selection" xsi:type="multiselect" visible="true" sort_order="3" source_model="NicolasBejean\CategoryWidget\Model\Config\Source\CategoryList">
-                <label translate="true">category_selection</label>
-                <description translate="true">category_selection_description</description>
+                <label>category_selection</label>
+                <description>category_selection_description</description>
             </parameter>
             <parameter name="category_image_width" xsi:type="text" visible="true" sort_order="4">
-                <label translate="true">category_image_width</label>
-                <description translate="true">category_image_width_description</description>
+                <label>category_image_width</label>
+                <description>category_image_width_description</description>
             </parameter>
             <parameter name="category_image_height" xsi:type="text" visible="true" sort_order="5">
-                <label translate="true">category_image_height</label>
-                <description translate="true">category_image_height_description</description>
+                <label>category_image_height</label>
+                <description>category_image_height_description</description>
             </parameter>
             <parameter name="template" xsi:type="select" required="true" visible="true" sort_order="6">
-                <label translate="true">template</label>
+                <label>template</label>
                 <options>
                     <option name="img_background" value="widget/category_widget_img_background.phtml" selected="true">
-                        <label translate="true">default_template</label>
+                        <label>default_template</label>
                     </option>
                     <option name="default" value="widget/category_widget.phtml">
-                        <label translate="true">other_template</label>
+                        <label>other_template</label>
                     </option>
                 </options>
             </parameter>
-- 
GitLab