src/Controller/ContactController.php line 72

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactFormType;
  4. use App\Services\GeneralSendMailService;
  5. use App\Services\MailService;
  6. use App\Services\CheckwebsitesettingService;
  7. use App\Services\ReCaptchaService;
  8. use Pimcore\Controller\FrontendController;
  9. use Pimcore\Mail;
  10. use Pimcore\Config\Config;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Pimcore\Translation\Translator;
  14. use Symfony\Component\Mailer\Transport;
  15. use Symfony\Component\Mailer\Mailer;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use MultilingualBundle\Service\DocumentLookupService;
  19. class ContactController extends BaseController
  20. {
  21.     protected $recaptcha;
  22.     protected $recaptchaVersion;
  23.     protected $recaptchaPublicKey;
  24.     protected $checkwebsitesettingService;
  25.     protected $inotherlang;
  26.     protected $translator;
  27.     protected $sendmail;
  28.     protected $currentLanguage;
  29.     public function __construct(CheckwebsitesettingService $checkwebsitesettingServiceDocumentLookupService $inotherlangTranslator $translatorReCaptchaService $recaptchaGeneralSendMailService $sendmail){
  30.         $this->checkwebsitesettingService $checkwebsitesettingService;
  31.         $this->inotherlang $inotherlang;
  32.         $this->translator $translator;
  33.         $this->recaptcha $recaptcha;
  34.         $this->recaptchaVersion $recaptcha->getVersion();
  35.         $this->recaptchaPublicKey $recaptcha->getPublicKey();
  36.         $this->sendmail $sendmail;
  37.     }
  38.     ////////////////////// General forms
  39.     ///
  40.     /**
  41.      *
  42.      * @param Request $request
  43.      * @param Translator $translator
  44.      *
  45.      * @return Response
  46.      *
  47.      * @throws \Exception
  48.      */
  49.     public function defaultAction(Request $request)
  50.     {
  51.         //
  52.         $formName ContactFormType::class;
  53.         $emailTemplate 'email_contact';           // Email template contact
  54.         $emailTemplateConfirm 'email_customer';   // Email template contact confirm
  55.         ///////// EDIT VARIABLES ABOVE
  56.         $this->currentLanguage $request->getLocale();
  57.         return $this->_defaultForm($request$formName$this->recaptchaVersion$emailTemplate$emailTemplateConfirm);
  58.     }
  59.     ///////////////////////// End general forms
  60.     protected function _defaultForm(Request $request$formName$recaptcha NULL$emailTemplate NULL$emailTemplateConfirm NULL)
  61.     {
  62.         $success false;
  63.         // initialize form and handle request data
  64.         if($formName){
  65.             $form $this->createForm($formName);
  66.             $form->handleRequest($request);
  67.         }
  68.         // handle form
  69.         if ($form->isSubmitted()) {
  70.             if ($form->isValid()) {
  71.                 $params $request->request->all();
  72.                 $message "Bedankt voor uw bericht. We nemen zo snel mogelijk contact met u op!";
  73.                 if($recaptcha){
  74.                     if($this->recaptcha->captchaverify($params)){
  75.                         $success true;
  76.                         $data $form->getData();
  77.                         $this->sendmail->_sendMailDefaultForm($data"$emailTemplate""$emailTemplateConfirm""$message",null,$request);
  78.                     }else{
  79.                         $message "Captcha code is niet correct!";
  80.                         $this->addFlash("warning"$message);
  81.                     }
  82.                 }else{
  83.                     $success true;
  84.                     $data $form->getData();
  85.                     $this->sendmail->_sendMailDefaultForm($data"$emailTemplate""$emailTemplateConfirm""$message",null,$request);
  86.                 }
  87.             }
  88.         }
  89.         return $this->render('contact/default.html.twig', [
  90.             'form' => $form->createView(),
  91.             'recaptcha' => $this->recaptchaVersion,
  92.             'recaptchaPublic' => $this->recaptchaPublicKey,
  93.             'success' => $success
  94. //            'error' => $error,
  95. //            'hideBreadcrumbs' => true
  96.         ]);
  97.     }
  98. }