From 39ef41eab232be81c72ace224580d86d21886485 Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:20:03 +0200 Subject: [PATCH 1/8] Add WidgetInterface to this module --- is_imageslider.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/is_imageslider.php b/is_imageslider.php index 1faf62c..ef4391c 100644 --- a/is_imageslider.php +++ b/is_imageslider.php @@ -14,8 +14,10 @@ use Oksydan\IsImageslider\Installer\ImageSliderInstaller; use PrestaShop\PrestaShop\Adapter\SymfonyContainer; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; +use PrestaShop\PrestaShop\Core\Module\WidgetInterface; -class Is_imageslider extends Module + +class Is_imageslider extends Module implements WidgetInterface { public $multistoreCompatibility = self::MULTISTORE_COMPATIBILITY_YES; @@ -140,4 +142,16 @@ private function getHookObject($methodName) return $hook instanceof HookInterface ? $hook : null; } + + public function renderWidget($hookName, array $configuration) + { + $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->renderWidget($configuration); + } + + public function getWidgetVariables($hookName, array $configuration) + { + $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->getWidgetVariables($configuration); + } } From 4d6ae0bd49bec5a7d7a21d540d66c2588af0dea8 Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:24:13 +0200 Subject: [PATCH 2/8] Add WidgetInterface to this module --- config/common.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/common.yml b/config/common.yml index fab5609..37dc1fe 100644 --- a/config/common.yml +++ b/config/common.yml @@ -74,6 +74,12 @@ services: parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook' public: true + # Modification of the module into a widget + oksydan.is_imageslider.hook.widget_capability: + class: Oksydan\IsImageslider\Hook\WidgetCapability + parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook' + public: true + oksydan.is_imageslider.cache.template_cache: class: Oksydan\IsImageslider\Cache\TemplateCache public: true From eed00e49f6a7873329367f41635141db92b1e290 Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:25:20 +0200 Subject: [PATCH 3/8] Add WidgetInterface to this module --- src/Hook/WidgetCapability.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Hook/WidgetCapability.php diff --git a/src/Hook/WidgetCapability.php b/src/Hook/WidgetCapability.php new file mode 100644 index 0000000..fa198ec --- /dev/null +++ b/src/Hook/WidgetCapability.php @@ -0,0 +1,55 @@ +context->isMobile() ? 'mobile' : 'desktop'); + } + + + /** + * @return array + */ + private function getSlides(): array + { + $now = new \DateTime(); + $slides = $this->slideRepository->getActiveSliderByLandAndStoreId( + $this->context->language->id, + $this->context->shop->id, + true, + 0, // 0 means no limit + $now + ); + + foreach ($slides as &$slide) { + $slide = $this->slidePresenter->present($slide); + } + + return $slides; + } + public function getWidgetVariables($params): array + { + return [ + 'homeslider' => [ + 'slides' => $this->getSlides(), + 'speed' => $this->sliderConfiguration->getSliderSpeed(), + 'pause' => $this->sliderConfiguration->getSliderPauseOnHover(), + 'wrap' => $this->sliderConfiguration->getSliderWrap(), + ], + ]; + } + + public function renderWidget($params) { + return $this->execute($params); + } +} \ No newline at end of file From d6ce18f0910c9ae081f5739c542b25371a585d7d Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:55:53 +0200 Subject: [PATCH 4/8] Update is_imageslider.php (PHP-CS-Fixer) --- is_imageslider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/is_imageslider.php b/is_imageslider.php index ef4391c..b360f37 100644 --- a/is_imageslider.php +++ b/is_imageslider.php @@ -13,9 +13,8 @@ use Oksydan\IsImageslider\Hook\HookInterface; use Oksydan\IsImageslider\Installer\ImageSliderInstaller; use PrestaShop\PrestaShop\Adapter\SymfonyContainer; -use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use PrestaShop\PrestaShop\Core\Module\WidgetInterface; - +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; class Is_imageslider extends Module implements WidgetInterface { @@ -146,12 +145,14 @@ private function getHookObject($methodName) public function renderWidget($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->renderWidget($configuration); } public function getWidgetVariables($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->getWidgetVariables($configuration); } } From beb20499ff569a8608c691605075c1461376a661 Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:00:31 +0200 Subject: [PATCH 5/8] Update is_imageslider.php (PHP-CS-Fixer Ok) --- is_imageslider.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/is_imageslider.php b/is_imageslider.php index b360f37..ef4391c 100644 --- a/is_imageslider.php +++ b/is_imageslider.php @@ -13,8 +13,9 @@ use Oksydan\IsImageslider\Hook\HookInterface; use Oksydan\IsImageslider\Installer\ImageSliderInstaller; use PrestaShop\PrestaShop\Adapter\SymfonyContainer; -use PrestaShop\PrestaShop\Core\Module\WidgetInterface; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; +use PrestaShop\PrestaShop\Core\Module\WidgetInterface; + class Is_imageslider extends Module implements WidgetInterface { @@ -145,14 +146,12 @@ private function getHookObject($methodName) public function renderWidget($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); - return $widgetCapability->renderWidget($configuration); } public function getWidgetVariables($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); - return $widgetCapability->getWidgetVariables($configuration); } } From d7f2175f896ddc48cd27577850e9ab31f8f093ff Mon Sep 17 00:00:00 2001 From: Guiraud Yoan <37932069+yoan82@users.noreply.github.com> Date: Tue, 12 Sep 2023 12:02:02 +0200 Subject: [PATCH 6/8] Update WidgetCapability.php (PHP-CS-Fixer Ok) --- src/Hook/WidgetCapability.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hook/WidgetCapability.php b/src/Hook/WidgetCapability.php index fa198ec..18a4e90 100644 --- a/src/Hook/WidgetCapability.php +++ b/src/Hook/WidgetCapability.php @@ -52,4 +52,4 @@ public function getWidgetVariables($params): array public function renderWidget($params) { return $this->execute($params); } -} \ No newline at end of file +} From d74910085619b44e8d235f2cd9aa8e897fba48ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Tue, 19 Sep 2023 22:43:48 +0200 Subject: [PATCH 7/8] CS-fixer fix --- is_imageslider.php | 5 +++-- src/Hook/WidgetCapability.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/is_imageslider.php b/is_imageslider.php index ef4391c..b360f37 100644 --- a/is_imageslider.php +++ b/is_imageslider.php @@ -13,9 +13,8 @@ use Oksydan\IsImageslider\Hook\HookInterface; use Oksydan\IsImageslider\Installer\ImageSliderInstaller; use PrestaShop\PrestaShop\Adapter\SymfonyContainer; -use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use PrestaShop\PrestaShop\Core\Module\WidgetInterface; - +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; class Is_imageslider extends Module implements WidgetInterface { @@ -146,12 +145,14 @@ private function getHookObject($methodName) public function renderWidget($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->renderWidget($configuration); } public function getWidgetVariables($hookName, array $configuration) { $widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability'); + return $widgetCapability->getWidgetVariables($configuration); } } diff --git a/src/Hook/WidgetCapability.php b/src/Hook/WidgetCapability.php index 18a4e90..8e07ec0 100644 --- a/src/Hook/WidgetCapability.php +++ b/src/Hook/WidgetCapability.php @@ -16,7 +16,6 @@ protected function getCacheKey(): string return parent::getCacheKey() . '_' . ($this->context->isMobile() ? 'mobile' : 'desktop'); } - /** * @return array */ @@ -37,6 +36,7 @@ private function getSlides(): array return $slides; } + public function getWidgetVariables($params): array { return [ @@ -49,7 +49,8 @@ public function getWidgetVariables($params): array ]; } - public function renderWidget($params) { + public function renderWidget($params) + { return $this->execute($params); } } From 0485c659aac24157b5983a9a77dd3249c1916114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Tue, 19 Sep 2023 23:08:00 +0200 Subject: [PATCH 8/8] Assign variables fix --- src/Hook/WidgetCapability.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Hook/WidgetCapability.php b/src/Hook/WidgetCapability.php index 8e07ec0..bfd04ca 100644 --- a/src/Hook/WidgetCapability.php +++ b/src/Hook/WidgetCapability.php @@ -49,7 +49,12 @@ public function getWidgetVariables($params): array ]; } - public function renderWidget($params) + protected function assignTemplateVariables(array $params) + { + $this->context->smarty->assign($this->getWidgetVariables($params)); + } + + public function renderWidget($params): string { return $this->execute($params); }