Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension hook to control file attachments per recipient and field #1252

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
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);
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down