app/Plugin/AddOnForCategory4/EventSubscriber/Controller/Admin/Product/CategoryControllerSubscriber.php line 48

Open in your IDE?
  1. <?php
  2. namespace Plugin\AddOnForCategory4\EventSubscriber\Controller\Admin\Product;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Eccube\Common\EccubeConfig;
  5. use Eccube\Event\TemplateEvent;
  6. use Eccube\Event\EventArgs;
  7. use Eccube\Event\EccubeEvents;
  8. use Symfony\Component\Filesystem\Filesystem;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. class CategoryControllerSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var EccubeConfig
  14.      */
  15.     private $eccubeConfig;
  16.     /**
  17.      * Event constructor.
  18.      * @param EccubeConfig $eccubeConfig
  19.      */
  20.     public function __construct(
  21.         EccubeConfig $eccubeConfig
  22.     ) {
  23.         $this->eccubeConfig $eccubeConfig;
  24.     }
  25.     /**
  26.      * @return array
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             '@admin/Product/category.twig' => ['AdminProductCategory'1],
  32.             EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE => 'AdminProductCategoryIndexComplete',
  33.         ];
  34.     }
  35.     /**
  36.      * @param TemplateEvent $event
  37.      */
  38.     public function AdminProductCategory(TemplateEvent $event)
  39.     {
  40.         $event->addSnippet('@AddOnForCategory4/admin/Product/admin_product_category.twig');
  41.     }
  42.     public function AdminProductCategoryIndexComplete(EventArgs $event)
  43.     {
  44.         $add_category_image null;
  45.         $form $event->getArgument('form');
  46.         $TargetCategory $event->getArgument('TargetCategory');
  47.         if($form->get('AddOnForCategory')->getData() != null) {
  48.             $add_category_image $form->get('AddOnForCategory')->getData()->getCategoryImage();
  49.         }
  50.         if ($TargetCategory) {
  51.             if($TargetCategory->getAddOnForCategory() !== null && $TargetCategory->getAddOnForCategory()->getCategoryImage() !== null){
  52.                 $add_category_image $TargetCategory->getAddOnForCategory()->getCategoryImage();
  53.             }
  54.         }
  55.         // 移動
  56.         if ($add_category_image) {
  57.             $file_path $this->eccubeConfig['eccube_temp_image_dir'] . '/' $add_category_image;
  58.             if (file_exists($file_path)) {
  59.                 $file = new File($file_path);
  60.                 $file->move($this->eccubeConfig['eccube_save_image_dir']);
  61.             }
  62.         }
  63.     }
  64. }