src/Eccube/Controller/ContactController.php line 59

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;
  13. use Eccube\Entity\Customer;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\Front\ContactType;
  17. use Eccube\Repository\PageRepository;
  18. use Eccube\Service\MailService;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class ContactController extends AbstractController
  23. {
  24.     /**
  25.      * @var MailService
  26.      */
  27.     protected $mailService;
  28.     /**
  29.      * @var PageRepository
  30.      */
  31.     private $pageRepository;
  32.     /**
  33.      * ContactController constructor.
  34.      *
  35.      * @param MailService $mailService
  36.      * @param PageRepository $pageRepository
  37.      */
  38.     public function __construct(
  39.         MailService $mailService,
  40.         PageRepository $pageRepository)
  41.     {
  42.         $this->mailService $mailService;
  43.         $this->pageRepository $pageRepository;
  44.     }
  45.     /**
  46.      * お問い合わせ画面.
  47.      *
  48.      * @Route("/contact", name="contact", methods={"GET", "POST"})
  49.      * @Route("/contact", name="contact_confirm", methods={"GET", "POST"})
  50.      * @Template("Contact/index.twig")
  51.      */
  52.     public function index(Request $request)
  53.     {
  54.         $builder $this->formFactory->createBuilder(ContactType::class);
  55.         if ($this->isGranted('ROLE_USER')) {
  56.             /** @var Customer $user */
  57.             $user $this->getUser();
  58.             $builder->setData(
  59.                 [
  60.                     'name01' => $user->getName01(),
  61.                     'name02' => $user->getName02(),
  62.                     'kana01' => $user->getKana01(),
  63.                     'kana02' => $user->getKana02(),
  64.                     'postal_code' => $user->getPostalCode(),
  65.                     'pref' => $user->getPref(),
  66.                     'addr01' => $user->getAddr01(),
  67.                     'addr02' => $user->getAddr02(),
  68.                     'phone_number' => $user->getPhoneNumber(),
  69.                     'email' => $user->getEmail(),
  70.                 ]
  71.             );
  72.         }
  73.         // FRONT_CONTACT_INDEX_INITIALIZE
  74.         $event = new EventArgs(
  75.             [
  76.                 'builder' => $builder,
  77.             ],
  78.             $request
  79.         );
  80.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  81.         $form $builder->getForm();
  82.         $form->handleRequest($request);
  83.         if ($form->isSubmitted() && $form->isValid()) {
  84.             switch ($request->get('mode')) {
  85.                 case 'confirm':
  86.                     return $this->render('Contact/confirm.twig', [
  87.                         'form' => $form->createView(),
  88.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  89.                     ]);
  90.                 case 'complete':
  91.                     $data $form->getData();
  92.                     $event = new EventArgs(
  93.                         [
  94.                             'form' => $form,
  95.                             'data' => $data,
  96.                         ],
  97.                         $request
  98.                     );
  99.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  100.                     $data $event->getArgument('data');
  101.                     // メール送信
  102.                     $this->mailService->sendContactMail($data);
  103.                     return $this->redirect($this->generateUrl('contact_complete'));
  104.             }
  105.         }
  106.         return [
  107.             'form' => $form->createView(),
  108.         ];
  109.     }
  110.     /**
  111.      * お問い合わせ完了画面.
  112.      *
  113.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  114.      * @Template("Contact/complete.twig")
  115.      */
  116.     public function complete()
  117.     {
  118.         return [];
  119.     }
  120. }