|
1
|
|
|
<?php |
|
2
|
|
|
namespace Qbus\Qbtools\ViewHelpers\Widget; |
|
3
|
|
|
|
|
4
|
|
|
use TYPO3\CMS\Extbase\Mvc\ResponseInterface; |
|
5
|
|
|
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper; |
|
6
|
|
|
use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper; |
|
7
|
|
|
use Qbus\Qbtools\ViewHelpers\Widget\Controller\MailformController; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Mailform widget with configurable form fields |
|
11
|
|
|
* |
|
12
|
|
|
* Example: |
|
13
|
|
|
* |
|
14
|
|
|
* {namespace q=Qbus\Qbtools\ViewHelpers} |
|
15
|
|
|
* <q:widget.mailform recipient="{mail: '[email protected]', name: 'Receiver Name'}" |
|
16
|
|
|
* required="{0: 'firstname', 1: 'lastname', 2: 'email'}" |
|
17
|
|
|
* mailTemplate="EXT:your_site/Resources/Private/Templates/Mailform/Mail.txt"> |
|
18
|
|
|
* <div class="qbtools-mailform-notification"> |
|
19
|
|
|
* <div class="alert alert-success" data-status="success" style="display: none">You message has not been sent.</div> |
|
20
|
|
|
* <div class="alert alert-danger" data-status="fields-missing" style="display: none">Fields marked with * have to be filled.</div> |
|
21
|
|
|
* <div class="alert alert-danger" data-status="error" style="display: none">Your E-Mail could not be sent. An internal error happended.</div> |
|
22
|
|
|
* </div> |
|
23
|
|
|
* <f:form.textfield name="firstname" required="true" id="{qbmailformid}-firstname" class="form-control" placeholder="Firstname *" /> |
|
24
|
|
|
* <f:form.textfield name="lastname" required="true" id="{qbmailformid}-lastname" class="form-control" placeholder="Lastname *" /> |
|
25
|
|
|
* <f:form.textfield name="email" required="true" type="email" id="{qbmailformid}-email" class="form-control" placeholder="E-Mail *"/> |
|
26
|
|
|
* <f:form.submit value="Anfrage absenden"/> |
|
27
|
|
|
* </q:widget.mailform> |
|
28
|
|
|
* |
|
29
|
|
|
* NOTE: You may set config.tx_qbtools.mailform.receiver.overwrite.email = [email protected] |
|
30
|
|
|
* |
|
31
|
|
|
* TODO: accept required as string-list |
|
32
|
|
|
* TODO: accept required list with conditions? |
|
33
|
|
|
* TODO: accept recipient as simple string containing only the mail address |
|
34
|
|
|
*/ |
|
35
|
|
|
class MailformViewHelper extends AbstractWidgetViewHelper |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @var bool |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $ajaxWidget = true; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var bool |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $storeConfigurationInSession = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var MailformController |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $controller; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param MailformController $controller |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
public function injectController(MailformController $controller) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->controller = $controller; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Initialize arguments |
|
63
|
|
|
*/ |
|
64
|
|
|
public function initializeArguments() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->registerArgument('recipient', 'array', "['email' => 'mail@address', 'name' => 'Full Name']", true); |
|
67
|
|
|
$this->registerArgument('sender', 'array', "['email' => 'mail@address', 'name' => 'Full Name']", false, null); |
|
68
|
|
|
$this->registerArgument('required', 'array', "['firstname', 'lastname', 'email']", false, ['firstname', 'lastname', 'email', 'message']); |
|
69
|
|
|
$this->registerArgument('mailTemplate', 'string', '', false, 'EXT:qbtools/Resources/Private/Templates/Mailform/Mail.txt'); |
|
70
|
|
|
$this->registerArgument('cc', 'array', "['email' => 'mail@address', 'name' => 'Full Name']", false, null); |
|
71
|
|
|
$this->registerArgument('bcc', 'array', "['email' => 'mail@address', 'name' => 'Full Name']", false, null); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return ResponseInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
public function render(): ResponseInterface |
|
78
|
|
|
{ |
|
79
|
|
|
/* <f:renderChildren> does not include the variable context from the subrequest-controller, |
|
80
|
|
|
* therefore we set the desired variables here. */ |
|
81
|
|
|
$this->viewHelperVariableContainer->add(FormViewHelper::class, 'fieldNamePrefix', 'msg'); |
|
82
|
|
|
$result = $this->initiateSubRequest(); |
|
83
|
|
|
$this->viewHelperVariableContainer->remove(FormViewHelper::class, 'fieldNamePrefix'); |
|
84
|
|
|
|
|
85
|
|
|
return $result; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|