-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShareThisEvent.php
executable file
·37 lines (31 loc) · 1.11 KB
/
ShareThisEvent.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
<?php
namespace Plugin\ShareThis;
use Eccube\Event\TemplateEvent;
use Plugin\ShareThis\Repository\ShareThisConfigRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ShareThisEvent implements EventSubscriberInterface
{
private ShareThisConfigRepository $configRepository;
public function __construct(ShareThisConfigRepository $configRepository)
{
$this->configRepository = $configRepository;
}
public static function getSubscribedEvents()
{
return [
'Product/detail.twig'=>'productDetail'
];
}
public function productDetail(TemplateEvent $event)
{
$config=$this->configRepository->get();
if (!is_null($config)){
$event->addSnippet('ShareThis/Resource/template/default/share.html.twig');
$params=$event->getParameters();
$params['property_id']=$config->getPropertyId();
$params['display_inline']=$config->isDisplayInline();
$params['inline_selector']=$config->getInlineSelector()?:'.ec-productRole__title';
$event->setParameters($params);
}
}
}