app/Customize/EventListener/BlockEventSubscriber.php line 38

Open in your IDE?
  1. <?php
  2. namespace Customize\EventListener;
  3. use Eccube\Event\TemplateEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Plugin\ECCUBE4LineLoginIntegration42\Entity\LineLoginIntegration;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. class BlockEventSubscriber implements EventSubscriberInterface {
  9.     private $em;
  10.     private $security;
  11.     public function __construct(EntityManagerInterface $emSecurity $security)
  12.     {
  13.         $this->em $em;
  14.         $this->security $security;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             'Block/top_carousel.twig' => 'onBlockTopCarousel',
  20.             'Block/top_carousel_sp.twig' => 'onBlockTopCarouselSp',
  21.             'Block/feature_banner.twig' => 'onBlockFeatureBanner',
  22.         ];
  23.     }
  24.     public function onBlockTopCarousel(TemplateEvent $event)
  25.     {
  26.         $event->setParameter('isLineLinked'$this->getLineStatus());
  27.     }
  28.     public function onBlockTopCarouselSp(TemplateEvent $event)
  29.     {
  30.         $event->setParameter('isLineLinked'$this->getLineStatus());
  31.     }
  32.     public function onBlockFeatureBanner(TemplateEvent $event)
  33.     {
  34.         $event->setParameter('isLineLinked'$this->getLineStatus());
  35.     }
  36.     private function getLineStatus()
  37.     {
  38.         $customer $this->security->getUser();
  39.         if (!$customer) {
  40.             return false;
  41.         }
  42.         $repo $this->em->getRepository(LineLoginIntegration::class);
  43.         return (bool) $repo->findOneBy(['Customer' => $customer]);
  44.     }
  45. }