src/Eccube/Controller/Admin/Setting/Shop/ShopController.php line 62

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 Eccube\Controller\Admin\Setting\Shop;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\Admin\ShopMasterType;
  17. use Eccube\Repository\BaseInfoRepository;
  18. use Eccube\Util\CacheUtil;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Twig\Environment;
  23. /**
  24.  * Class ShopController
  25.  */
  26. class ShopController extends AbstractController
  27. {
  28.     /**
  29.      * @var Environment
  30.      */
  31.     protected $twig;
  32.     /**
  33.      * @var BaseInfoRepository
  34.      */
  35.     protected $baseInfoRepository;
  36.     /**
  37.      * ShopController constructor.
  38.      *
  39.      * @param Environment $twig
  40.      * @param BaseInfoRepository $baseInfoRepository
  41.      */
  42.     public function __construct(Environment $twigBaseInfoRepository $baseInfoRepository)
  43.     {
  44.         $this->baseInfoRepository $baseInfoRepository;
  45.         $this->twig $twig;
  46.     }
  47.     /**
  48.      * @Route("/%eccube_admin_route%/setting/shop", name="admin_setting_shop", methods={"GET", "POST"})
  49.      * @Template("@admin/Setting/Shop/shop_master.twig")
  50.      *
  51.      * @param Request $request
  52.      *
  53.      * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  54.      */
  55.     public function index(Request $requestCacheUtil $cacheUtil)
  56.     {
  57.         $BaseInfo $this->baseInfoRepository->get();
  58.         $builder $this->formFactory
  59.             ->createBuilder(ShopMasterType::class, $BaseInfo);
  60.         $CloneInfo = clone $BaseInfo;
  61.         $this->entityManager->detach($CloneInfo);
  62.         $event = new EventArgs(
  63.             [
  64.                 'builder' => $builder,
  65.                 'BaseInfo' => $BaseInfo,
  66.             ],
  67.             $request
  68.         );
  69.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_SETTING_SHOP_SHOP_INDEX_INITIALIZE);
  70.         $form $builder->getForm();
  71.         $form->handleRequest($request);
  72.         if ($form->isSubmitted() && $form->isValid()) {
  73.             $this->entityManager->persist($BaseInfo);
  74.             $this->entityManager->flush();
  75.             $event = new EventArgs(
  76.                 [
  77.                     'form' => $form,
  78.                     'BaseInfo' => $BaseInfo,
  79.                 ],
  80.                 $request
  81.             );
  82.             $this->eventDispatcher->dispatch(
  83.                 $event,
  84.                 EccubeEvents::ADMIN_SETTING_SHOP_SHOP_INDEX_COMPLETE
  85.             );
  86.             // キャッシュの削除
  87.             $cacheUtil->clearDoctrineCache();
  88.             $this->addSuccess('admin.common.save_complete''admin');
  89.             return $this->redirectToRoute('admin_setting_shop');
  90.         }
  91.         $this->twig->addGlobal('BaseInfo'$CloneInfo);
  92.         return [
  93.             'form' => $form->createView(),
  94.         ];
  95.     }
  96. }