src/Eccube/Controller/ContactController.php line 49

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