app/Plugin/TwoFactorAuthCustomer42/Event.php line 73

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\TwoFactorAuthCustomer42;
  13. use Eccube\Event\TemplateEvent;
  14. use Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthTypeRepository;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * Class Event.
  18.  */
  19. class Event implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * @var bool
  23.      */
  24.     private bool $hasActiveAuthType;
  25.     /**
  26.      * Event constructor.
  27.      *
  28.      * @throws \Exception
  29.      */
  30.     public function __construct(TwoFactorAuthTypeRepository $twoFactorAuthTypeRepository)
  31.     {
  32.         $this->hasActiveAuthType $twoFactorAuthTypeRepository->count(['isDisabled' => false]) > 0;
  33.     }
  34.     public static function getSubscribedEvents(): array
  35.     {
  36.         return [
  37.             '@admin/Setting/Shop/shop_master.twig' => 'onRenderAdminShopSettingEdit',
  38.             '@admin/Customer/edit.twig' => 'onRenderAdminCustomerEdit',
  39.         ];
  40.     }
  41.     /**
  42.      * [/admin/setting/shop]表示の時のEvent Hook.
  43.      * SMS関連項目を追加する.
  44.      *
  45.      * @param TemplateEvent $event
  46.      */
  47.     public function onRenderAdminShopSettingEdit(TemplateEvent $event)
  48.     {
  49.         // add 本人確認認証 twig
  50.         $twig 'TwoFactorAuthCustomer42/Resource/template/admin/shop_edit_sms.twig';
  51.         $event->addSnippet($twig);
  52.         if ($this->hasActiveAuthType) {
  53.             // add 2段階認証設定 twig
  54.             $twig 'TwoFactorAuthCustomer42/Resource/template/admin/shop_edit_tfa.twig';
  55.             $event->addSnippet($twig);
  56.         }
  57.     }
  58.     /**
  59.      * [/admin/customer/edit]表示の時のEvent Hook.
  60.      * 二段階認証関連項目を追加する.
  61.      *
  62.      * @param TemplateEvent $event
  63.      */
  64.     public function onRenderAdminCustomerEdit(TemplateEvent $event)
  65.     {
  66.         // add twig
  67.         $twig 'TwoFactorAuthCustomer42/Resource/template/admin/customer_edit.twig';
  68.         $event->addSnippet($twig);
  69.     }
  70. }