2 declare(strict_types = 1);
62 'recipientName' =>
'',
65 'attachUploads' => true
76 $formRuntime = $this->finisherContext->getFormRuntime();
80 if (isset($this->options[
'translation'][
'language']) && !empty($this->options[
'translation'][
'language'])) {
81 $languageBackup = $translationService->getLanguage();
82 $translationService->setLanguage($this->options[
'translation'][
'language']);
84 $message = $standaloneView->render();
85 if (!empty($languageBackup)) {
86 $translationService->setLanguage($languageBackup);
90 $recipientAddress = $this->
parseOption(
'recipientAddress');
95 $carbonCopyAddress = $this->
parseOption(
'carbonCopyAddress');
96 $blindCarbonCopyAddress = $this->
parseOption(
'blindCarbonCopyAddress');
100 if (empty($subject)) {
101 throw new FinisherException(
'The option "subject" must be set for the EmailFinisher.', 1327060320);
103 if (empty($recipientAddress)) {
104 throw new FinisherException(
'The option "recipientAddress" must be set for the EmailFinisher.', 1327060200);
106 if (empty($senderAddress)) {
107 throw new FinisherException(
'The option "senderAddress" must be set for the EmailFinisher.', 1327060210);
110 $mail = $this->objectManager->get(MailMessage::class);
112 $mail->setFrom([$senderAddress => $senderName])
113 ->setTo([$recipientAddress => $recipientName])
114 ->setSubject($subject);
116 if (!empty($replyToAddress)) {
117 $mail->setReplyTo($replyToAddress);
120 if (!empty($carbonCopyAddress)) {
121 $mail->setCc($carbonCopyAddress);
124 if (!empty($blindCarbonCopyAddress)) {
125 $mail->setBcc($blindCarbonCopyAddress);
128 if ($format === self::FORMAT_PLAINTEXT) {
129 $mail->setBody($message,
'text/plain');
131 $mail->setBody($message,
'text/html');
134 $elements = $formRuntime->getFormDefinition()->getRenderablesRecursively();
136 if ($attachUploads) {
137 foreach ($elements as $element) {
141 $file = $formRuntime[$element->getIdentifier()];
144 $file = $file->getOriginalResource();
147 $mail->attach(\Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType()));
163 $standaloneView = $this->objectManager->get(StandaloneView::class);
165 if (isset($this->options[
'templatePathAndFilename'])) {
166 $this->options[
'templatePathAndFilename'] = strtr($this->options[
'templatePathAndFilename'], [
167 '{@format}' => $format
169 $standaloneView->setTemplatePathAndFilename($this->options[
'templatePathAndFilename']);
171 if (!isset($this->options[
'templateName'])) {
172 throw new FinisherException(
'The option "templateName" must be set for the EmailFinisher.', 1327058829);
174 $this->options[
'templateName'] = strtr($this->options[
'templateName'], [
175 '{@format}' => $format
177 $standaloneView->setTemplate($this->options[
'templateName']);
180 $standaloneView->assign(
'finisherVariableProvider', $this->finisherContext->getFinisherVariableProvider());
182 if (isset($this->options[
'templateRootPaths']) && is_array($this->options[
'templateRootPaths'])) {
183 $standaloneView->setTemplateRootPaths($this->options[
'templateRootPaths']);
186 if (isset($this->options[
'partialRootPaths']) && is_array($this->options[
'partialRootPaths'])) {
187 $standaloneView->setPartialRootPaths($this->options[
'partialRootPaths']);
190 if (isset($this->options[
'layoutRootPaths']) && is_array($this->options[
'layoutRootPaths'])) {
191 $standaloneView->setLayoutRootPaths($this->options[
'layoutRootPaths']);
194 if (isset($this->options[
'variables'])) {
195 $standaloneView->assignMultiple($this->options[
'variables']);
198 $standaloneView->assign(
'form', $formRuntime);
199 $standaloneView->getRenderingContext()
200 ->getViewHelperVariableContainer()
201 ->addOrUpdate(RenderRenderableViewHelper::class,
'formRuntime', $formRuntime);
203 return $standaloneView;