app/Plugin/Shiro8AddCart42/Shiro8AddCartEvent.php line 80

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  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\Shiro8AddCart42;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Eccube\Entity\Product;
  16. use Eccube\Event\TemplateEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Twig\Environment;
  20. class Shiro8AddCartEvent implements EventSubscriberInterface
  21. {
  22.     
  23.     /**
  24.      * @var EntityManagerInterface
  25.      */
  26.     private $entityManager;
  27.     
  28.     /**
  29.      * @var Environment
  30.      */
  31.     private $twig;
  32.     
  33.     /**
  34.      * Shiro8AddCartEvent constructor.
  35.      *
  36.      * @param EntityManagerInterface $entityManager
  37.      */
  38.     public function __construct(
  39.         EntityManagerInterface $entityManager,
  40.         Environment $twig
  41.     ) {
  42.         $this->entityManager $entityManager;
  43.         $this->twig $twig;
  44.     }
  45.     /**
  46.      * @return array
  47.      */
  48.     public static function getSubscribedEvents()
  49.     {
  50.         return [
  51.             '@admin/Product/product.twig' => 'onRenderAdminProductEdit',
  52.             '@admin/Product/product_class.twig' => 'onRenderAdminProductClassEdit',
  53.             '@Shiro8Download42/admin/Product/product_class.twig' => 'onRenderAdminProductClassEdit',
  54.         ];
  55.     }
  56.     
  57.     /**
  58.      * @param TemplateEvent $event
  59.      */
  60.     public function onRenderAdminProductEdit(TemplateEvent $event)
  61.     {
  62.         $parameters $event->getParameters();
  63.         
  64.         // twigコードにコンテンツを挿入
  65.         $snipet $this->twig->getLoader()->getSourceContext('@Shiro8AddCart42/admin/Product/product.twig')->getCode();
  66.         
  67.         $sourceOrigin $event->getSource();
  68.         $source str_replace('<div class="collapse show ec-cardCollapse" id="preview">'$snipet$sourceOrigin);
  69.         $event->setSource($source);
  70.     }
  71.     /**
  72.      * @param TemplateEvent $event
  73.      */
  74.     public function onRenderAdminProductClassEdit(TemplateEvent $event)
  75.     {
  76.         
  77.         $parameters $event->getParameters();
  78.         
  79.          // twigコードにコンテンツを挿入
  80.         $snipet $this->twig->getLoader()->getSourceContext('@Shiro8AddCart42/admin/Product/product_class.twig')->getCode();
  81.         $sourceOrigin $event->getSource();
  82.         $source str_replace('{{ form_widget(product_class_form.stock_unlimited) }}'$snipet$sourceOrigin);
  83.         $event->setSource($source);
  84.     }
  85. }