app/Plugin/DeliveryDate42/Event/AdminSettingEvent.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryDate4
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  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\DeliveryDate42\Event;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Eccube\Event\TemplateEvent;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class AdminSettingEvent implements EventSubscriberInterface
  18. {
  19.     private $entityManager;
  20.     public function __construct(
  21.             EntityManagerInterface $entityManager
  22.             )
  23.     {
  24.         $this->entityManager $entityManager;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             '@admin/Setting/Shop/delivery_edit.twig' => 'onTemplateAdminSettingShopDeliveryEdit',
  33.             EccubeEvents::ADMIN_SETTING_SHOP_DELIVERY_EDIT_COMPLETE => 'hookAdminSettingShopDeliveryEditComplete',
  34.         ];
  35.     }
  36.     public function onTemplateAdminSettingShopDeliveryEdit(TemplateEvent $event)
  37.     {
  38.         $twig '@DeliveryDate42/admin/Setting/Shop/delivery_date.twig';
  39.         $event->addSnippet($twig);
  40.         $js '@DeliveryDate42/admin/Setting/Shop/delivery_date.js';
  41.         $event->addAsset($js);
  42.     }
  43.     public function hookAdminSettingShopDeliveryEditComplete(EventArgs $event)
  44.     {
  45.         $form $event->getArgument('form');
  46.         $Delivery $event->getArgument('Delivery');
  47.         $DeliveryDates $form['delivery_dates']->getData();
  48.         foreach($DeliveryDates as $DeliveryDate){
  49.             $DeliveryDate->setDelivery($Delivery);
  50.             $Delivery->addDeliveryDate($DeliveryDate);
  51.             $this->entityManager->persist($DeliveryDate);
  52.         }
  53.         $this->entityManager->flush();
  54.     }
  55. }