app/Plugin/MembersOnly42/Event.php line 73

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of MembersOnly
  4.  *
  5.  * Copyright(c) Akira Kurozumi <info@a-zumi.net>
  6.  *
  7.  * https://a-zumi.net
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\MembersOnly42;
  13. use Eccube\Event\TemplateEvent;
  14. use Plugin\MembersOnly42\Repository\AccessControlRepository;
  15. use Plugin\MembersOnly42\Repository\ConfigRepository;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class Event implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var AccessControlRepository
  21.      */
  22.     private AccessControlRepository $accessControlRepository;
  23.     /**
  24.      * @var ConfigRepository
  25.      */
  26.     private ConfigRepository $configRepository;
  27.     public function __construct(
  28.         AccessControlRepository $accessControlRepository,
  29.         ConfigRepository $configRepository
  30.     ) {
  31.         $this->accessControlRepository $accessControlRepository;
  32.         $this->configRepository $configRepository;
  33.     }
  34.     /**
  35.      * @param TemplateEvent $templateEvent
  36.      *
  37.      * @return void
  38.      */
  39.     public function onTemplateMyPageLogin(TemplateEvent $templateEvent): void
  40.     {
  41.         $templateEvent->addSnippet('@MembersOnly42/default/Mypage/login_message.twig');
  42.     }
  43.     /**
  44.      * @param TemplateEvent $templateEvent
  45.      *
  46.      * @return void
  47.      *
  48.      * @throws \Exception
  49.      */
  50.     public function onTemplateProductList(TemplateEvent $templateEvent): void
  51.     {
  52.         $Config $this->configRepository->get();
  53.         if ($Config && $Config->getOptionPriceHidden()) {
  54.             $templateEvent->addSnippet('@MembersOnly42/default/Product/list.twig');
  55.         }
  56.     }
  57.     /**
  58.      * @param TemplateEvent $templateEvent
  59.      *
  60.      * @return void
  61.      *
  62.      * @throws \Exception
  63.      */
  64.     public function onTemplateProductDetail(TemplateEvent $templateEvent): void
  65.     {
  66.         $Config $this->configRepository->get();
  67.         if ($Config && $Config->getOptionPriceHidden()) {
  68.             $templateEvent->addSnippet('@MembersOnly42/default/Product/detail.twig');
  69.         }
  70.     }
  71.     /**
  72.      * @return array[]
  73.      */
  74.     public static function getSubscribedEvents(): array
  75.     {
  76.         return [
  77.             'Mypage/login.twig' => ['onTemplateMyPageLogin', -256],
  78.             'Product/list.twig' => ['onTemplateProductList', -256],
  79.             'Product/detail.twig' => ['onTemplateProductDetail', -256],
  80.         ];
  81.     }
  82. }