app/Plugin/DesignTag4/Event.php line 61

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of DesignTag4
  4.  * Copyright(c) U-Mebius Inc. All Rights Reserved.
  5.  *
  6.  * https://umebius.com/
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Plugin\DesignTag4;
  12. use Eccube\Common\Constant;
  13. use Eccube\Event\TemplateEvent;
  14. use Eccube\Repository\TagRepository;
  15. use Plugin\DesignTag4\Service\TwigService;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class Event implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var TwigService
  21.      */
  22.     private $twigService;
  23.     /**
  24.      * @var TagRepository
  25.      */
  26.     private $tagRepository;
  27.     public function __construct(
  28.         TwigService $twigService,
  29.         TagRepository $tagRepository
  30.     ) {
  31.         $this->tagRepository $tagRepository;
  32.         $this->twigService $twigService;
  33.     }
  34.     /**
  35.      * @return array
  36.      */
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [
  40.             '@admin/Product/tag.twig' => 'onAdminProductTagTwig',
  41.             'Product/detail.twig' => 'onProductDetailTwig',
  42.             'Product/list.twig' => 'onProductListTwig',
  43.         ];
  44.     }
  45.     public function onAdminProductTagTwig(TemplateEvent $event)
  46.     {
  47.         $event->addSnippet('@DesignTag4/admin/Product/tag.twig');
  48.         if (version_compare(Constant::VERSION'4.0.3') <= 0) {
  49.             $event->addSnippet('@DesignTag4/admin/Product/tag_lte_4_0_3.twig');
  50.         }
  51.     }
  52.     public function onProductDetailTwig(TemplateEvent $event)
  53.     {
  54.         $Product $event->getParameter('Product');
  55.         $DesignTags $Product->getTags();
  56.         $event->setParameter('DesignTags'$DesignTags);
  57.         $event->addAsset('@DesignTag4/tag_detail_css.twig');
  58.     }
  59.     public function onProductListTwig(TemplateEvent $event)
  60.     {
  61. //        $insert = $this->twigService->getTwigFile('@DesignTag4/tag_list.twig');
  62. //        $this->twigService->setSource($event->getSource());
  63. //        $this->twigService->insert('<p>{{ Product.name }}</p>', $insert);
  64. //        $event->setSource($this->twigService->getSource());
  65.         $DesignTags $this->tagRepository->findBy(['show_product_list_flg' => true]);
  66.         $event->setParameter('DesignTags'$DesignTags);
  67.         $event->addAsset('@DesignTag4/tag_list_css.twig');
  68.     }
  69. }