Initial Commit
This commit is contained in:
85
local/modules/SliderRevolution/Hook/FrontHookManager.php
Normal file
85
local/modules/SliderRevolution/Hook/FrontHookManager.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Copyright (c) Franck Allimant, CQFDev */
|
||||
/* email : thelia@cqfdev.fr */
|
||||
/* web : http://www.cqfdev.fr */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
/**
|
||||
* Created by Franck Allimant, CQFDev <franck@cqfdev.fr>
|
||||
* Date: 05/03/2016 18:11
|
||||
*/
|
||||
|
||||
namespace SliderRevolution\Hook;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use SliderRevolution\Model\SliderAssociationQuery;
|
||||
use SliderRevolution\SliderRevolution;
|
||||
use Thelia\Core\Event\Hook\HookRenderEvent;
|
||||
use Thelia\Core\Hook\BaseHook;
|
||||
|
||||
require_once __DIR__ . "/../../../../web/revslider/embed_thelia.php";
|
||||
|
||||
class FrontHookManager extends BaseHook
|
||||
{
|
||||
private $jsCode = '';
|
||||
|
||||
public function onMainStylesheet(HookRenderEvent $event)
|
||||
{
|
||||
if (null !== SliderRevolution::getConfigValue(SliderRevolution::SLIDER_ID)) {
|
||||
$event->add(
|
||||
\RevSliderEmbedder::cssIncludes(false)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function onMainJavascriptInitialization(HookRenderEvent $event)
|
||||
{
|
||||
if (null !== SliderRevolution::getConfigValue(SliderRevolution::SLIDER_ID)) {
|
||||
$event->add(
|
||||
\RevSliderEmbedder::jsIncludes(false, false) . $this->jsCode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function onMainContentTop(HookRenderEvent $event)
|
||||
{
|
||||
$view = $this->getView();
|
||||
|
||||
if ($this->isAcceptedView($view)) {
|
||||
if ($view === "index") {
|
||||
if (null !== $slider = SliderRevolution::getConfigValue(SliderRevolution::SLIDER_ID)) {
|
||||
$event->add(
|
||||
\RevSliderEmbedder::putRevSlider($slider, '', $this->jsCode)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (null !== $sliderAssoc = SliderAssociationQuery::create()
|
||||
->filterByObjectType($view)
|
||||
->filterByObjectId( $this->getRequest()->get($view . '_id'))
|
||||
->filterBySliderAlias('', Criteria::NOT_EQUAL)
|
||||
->findOne()) {
|
||||
$event->add(
|
||||
\RevSliderEmbedder::putRevSlider($sliderAssoc->getSliderAlias(), '', $this->jsCode)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function isAcceptedView($view)
|
||||
{
|
||||
$acceptedViews = [
|
||||
'category',
|
||||
'product',
|
||||
'folder',
|
||||
'content',
|
||||
'brand',
|
||||
'index'
|
||||
];
|
||||
|
||||
return in_array($view, $acceptedViews);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user