Skip to content

Commit

Permalink
Merge pull request #1252 from michalkleiner/pulls/1203-attach-file-pe…
Browse files Browse the repository at this point in the history
…r-recipient-hook

Add extension hook to control file attachments per recipient and field
  • Loading branch information
GuySartorelli authored Nov 12, 2023
2 parents 79e1fb8 + 26a4816 commit 4b85a33
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions code/Control/UserDefinedFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ public function process($data, $form)

// attach a file to recipient email only if lower than configured size
if ($file->getAbsoluteSize() <= $this->getMaximumAllowedEmailAttachmentSize()) {
$attachments[] = $file;
// using the field name as array index is fine as file upload field only allows one file
$attachments[$field->Name] = $file;
}
}
}
Expand Down Expand Up @@ -393,17 +394,22 @@ public function process($data, $form)
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);

if ($attachments && (bool) $recipient->HideFormData === false) {
foreach ($attachments as $file) {
foreach ($attachments as $uploadFieldName => $file) {
/** @var File $file */
if ((int) $file->ID === 0) {
continue;
}

$email->addAttachmentFromData(
$file->getString(),
$file->getFilename(),
$file->getMimeType()
);
$canAttachFileForRecipient = true;
$this->extend('updateCanAttachFileForRecipient', $canAttachFileForRecipient, $recipient, $uploadFieldName, $file);

if ($canAttachFileForRecipient) {
$email->addAttachmentFromData(
$file->getString(),
$file->getFilename(),
$file->getMimeType()
);
}
}
}

Expand Down

0 comments on commit 4b85a33

Please sign in to comment.