Completed
Push — master ( f8f86d...f2374b )
by Ruud
17:35 queued 04:56
created

SendEmailListener::onSubmission()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
3
namespace Kunstmaan\FormBundle\EventListener;
4
5
use Kunstmaan\FormBundle\Event\SubmissionEvent;
6
use Kunstmaan\FormBundle\Helper\FormMailerInterface;
7
8
/**
9
 * An event listener for sending an email after the form submission is completed
10
 */
11
class SendEmailListener
12
{
13
    /**
14
     * @var FormMailerInterface
15
     */
16
    private $formMailer;
17
18
    /**
19
     * @param FormMailerInterface $formMailer The form Mailer
20
     */
21
    public function __construct(FormMailerInterface $formMailer)
22
    {
23
        $this->formMailer = $formMailer;
24
    }
25
26
    /**
27
     * Configure the form submissions link on top of the form in the sub action menu
28
     *
29
     * @param SubmissionEvent $event
30
     */
31
    public function onSubmission(SubmissionEvent $event)
32
    {
33
        $page = $event->getPage();
34
        $formSubmission = $event->getSubmission();
35
36
        $from = $page->getFromEmail();
37
        $to = $page->getToEmail();
38
        $subject = $page->getSubject();
39
        if (!empty($from) && !empty($to) && !empty($subject)) {
40
            $this->formMailer->sendContactMail($formSubmission, $from, $to, $subject);
41
        }
42
    }
43
}
44