Skip to content

Commit

Permalink
Add WidgetInterface to this module
Browse files Browse the repository at this point in the history
  • Loading branch information
yoan82 authored Sep 11, 2023
1 parent 41bb74b commit e338579
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Hook/WidgetCapability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Oksydan\IsImageslider\Hook;

class WidgetCapability extends AbstractCacheableDisplayHook
{
private const TEMPLATE_FILE = 'slider.tpl';

protected function getTemplate(): string
{
return WidgetCapability::TEMPLATE_FILE;
}

protected function getCacheKey(): string
{
return parent::getCacheKey() . '_' . ($this->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);
}
}

0 comments on commit e338579

Please sign in to comment.