3
3
namespace Uniform \Actions ;
4
4
5
5
use Exception ;
6
- use Uniform \Form ;
7
6
use Kirby \Cms \App ;
8
7
use Kirby \Toolkit \Str ;
9
8
use Kirby \Toolkit \I18n ;
@@ -100,12 +99,13 @@ protected function sendEmail(array $params)
100
99
}
101
100
102
101
/**
103
- * Get the email subject and resolve possible template strings
104
- *
102
+ * Resolve template strings
103
+ *
104
+ * @param string $string
105
+ *
105
106
* @return string
106
107
*/
107
- protected function getSubject ()
108
- {
108
+ protected function resolveTemplate ($ string ) {
109
109
// the form could contain arrays which are incompatible with the template function
110
110
$ templatableItems = array_filter ($ this ->form ->data (), function ($ item ) {
111
111
return is_scalar ($ item );
@@ -119,14 +119,24 @@ protected function getSubject()
119
119
$ fallback = '' ;
120
120
}
121
121
122
- $ subject = Str::template ($ this ->option ('subject ' , I18n::translate ('uniform-email-subject ' )), $ templatableItems , $ fallback );
122
+ return Str::template ($ string , $ templatableItems , $ fallback );
123
+ }
124
+
125
+ /**
126
+ * Get the email subject and resolve possible template strings
127
+ *
128
+ * @return string
129
+ */
130
+ protected function getSubject ()
131
+ {
132
+ $ subject = $ this ->resolveTemplate ($ this ->option ('subject ' , I18n::translate ('uniform-email-subject ' )));
123
133
124
134
// Remove newlines to prevent malicious modifications of the email header.
125
135
return str_replace ("\n" , '' , $ subject );
126
136
}
127
137
128
138
/**
129
- * Get the email body
139
+ * Get the email body and resolve possible template strings
130
140
*
131
141
* @param array $data
132
142
*
@@ -136,6 +146,11 @@ protected function getBody($data)
136
146
{
137
147
unset($ data [self ::EMAIL_KEY ]);
138
148
unset($ data [self ::RECEIVE_COPY_KEY ]);
149
+
150
+ if (isset ($ data ['body ' ])) {
151
+ return $ this ->resolveTemplate ($ data ['body ' ]);
152
+ }
153
+
139
154
$ body = '' ;
140
155
foreach ($ data as $ key => $ value ) {
141
156
if (is_array ($ value )) {
0 commit comments