app/Plugin/tbsMailTemplate42/tbsMailTemplateEvent.php line 43

Open in your IDE?
  1. <?php
  2. namespace Plugin\tbsMailTemplate42;
  3. use Doctrine\ORM\EntityRepository;
  4. use Eccube\Common\EccubeConfig;
  5. use Eccube\Event\EccubeEvents;
  6. use Eccube\Event\EventArgs;
  7. use Eccube\Event\TemplateEvent;
  8. use Eccube\Form\Type\Master\MailTemplateType;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class tbsMailTemplateEvent implements EventSubscriberInterface
  11. {
  12.     protected $eccubeConfig;
  13.     /**
  14.      * tbsMailTemplateEvent constructor.
  15.      */
  16.     public function __construct(EccubeConfig $eccubeConfig)
  17.     {
  18.         $this->eccubeConfig $eccubeConfig;
  19.     }
  20.     /**
  21.      * @return array
  22.      */
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             EccubeEvents::ADMIN_ORDER_MAIL_INDEX_INITIALIZE => 'adminOrderMailIndexInitialize',
  27.             '@admin/Order/edit.twig' => 'onRenderAdminOrderEdit',
  28.             'Mypage/history.twig' => 'onRenderMypageHistory',
  29.         ];
  30.     }
  31.     /**
  32.      * メールテンプレートの選択肢を追加する.
  33.      *
  34.      * @param TemplateEvent $event
  35.      */
  36.     public function adminOrderMailIndexInitialize(EventArgs $eventArgs)
  37.     {
  38.         $builder $eventArgs->getArgument('builder');
  39.         $builder->add('template'MailTemplateType::class, [
  40.             'required' => false,
  41.             'mapped' => false,
  42.             'query_builder' => function (EntityRepository $er) {
  43.                 return $er->createQueryBuilder('mt')
  44.                     ->andWhere('mt.id = :id or mt.id > :id_over')
  45.                     ->setParameter('id'$this->eccubeConfig['eccube_order_mail_template_id'])
  46.                     ->setParameter('id_over'$this->eccubeConfig['eccube_shipping_notify_mail_template_id'])
  47.                     ->orderBy('mt.id''ASC');
  48.             },
  49.         ]);
  50.     }
  51.     /**
  52.      * 管理画面受注登録にHTMLメール作成ボタンを表示する.
  53.      *
  54.      * @param TemplateEvent $event
  55.      */
  56.     public function onRenderAdminOrderEdit(TemplateEvent $event)
  57.     {
  58.         $event->addSnippet('@tbsMailTemplate42/admin/Order/edit.twig');
  59.     }
  60.     /**
  61.      * マイページ購入履歴のメール配信履歴にHTMLメールを表示する.
  62.      *
  63.      * @param TemplateEvent $event
  64.      */
  65.     public function onRenderMypageHistory(TemplateEvent $event)
  66.     {
  67.         $event->addSnippet('@tbsMailTemplate42/default/Mypage/history.twig');
  68.     }
  69. }