forked from FriendsOfShopware/FroshWebP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FroshWebP.php
57 lines (47 loc) · 1.43 KB
/
FroshWebP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace FroshWebP;
use FroshWebP\Services\WebpEncoders\PhpGd;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Models\Config\Element;
/**
* Class FroshWebP
*/
class FroshWebP extends Plugin
{
public static function getSubscribedEvents()
{
return [
'Shopware_Controllers_Backend_Config_Before_Save_Config_Element' => 'onConfigSave'
];
}
/**
* {@inheritdoc}
*/
public function install(InstallContext $context)
{
$gd = new PhpGd();
if (!$gd->isRunnable()) {
$context->scheduleMessage('PHP is not compiled with WebP Support. Please contact your Hosting provider!');
}
}
public function activate(ActivateContext $context)
{
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
public function deactivate(DeactivateContext $context)
{
$context->scheduleClearCache(DeactivateContext::CACHE_LIST_ALL);
}
public function onConfigSave(\Enlight_Event_EventArgs $args)
{
/** @var Element $element */
$element = $args->get('element');
if ($element->getName() !== 'enableWebPInFrontend') {
return;
}
$this->container->get('shopware.cache_manager')->clearTemplateCache();
}
}