mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #1252 from michalkleiner/pulls/1203-attach-file-per-recipient-hook
Add extension hook to control file attachments per recipient and field
This commit is contained in:
commit
4b85a33b5d
@ -355,7 +355,8 @@ JS
|
|||||||
|
|
||||||
// attach a file to recipient email only if lower than configured size
|
// attach a file to recipient email only if lower than configured size
|
||||||
if ($file->getAbsoluteSize() <= $this->getMaximumAllowedEmailAttachmentSize()) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,12 +394,16 @@ JS
|
|||||||
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
|
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
|
||||||
|
|
||||||
if ($attachments && (bool) $recipient->HideFormData === false) {
|
if ($attachments && (bool) $recipient->HideFormData === false) {
|
||||||
foreach ($attachments as $file) {
|
foreach ($attachments as $uploadFieldName => $file) {
|
||||||
/** @var File $file */
|
/** @var File $file */
|
||||||
if ((int) $file->ID === 0) {
|
if ((int) $file->ID === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$canAttachFileForRecipient = true;
|
||||||
|
$this->extend('updateCanAttachFileForRecipient', $canAttachFileForRecipient, $recipient, $uploadFieldName, $file);
|
||||||
|
|
||||||
|
if ($canAttachFileForRecipient) {
|
||||||
$email->addAttachmentFromData(
|
$email->addAttachmentFromData(
|
||||||
$file->getString(),
|
$file->getString(),
|
||||||
$file->getFilename(),
|
$file->getFilename(),
|
||||||
@ -406,6 +411,7 @@ JS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
|
if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
|
||||||
$email->setHTMLTemplate($recipient->EmailTemplate);
|
$email->setHTMLTemplate($recipient->EmailTemplate);
|
||||||
|
Loading…
Reference in New Issue
Block a user