public function WebformAttachmentBase::getEmailAttachments in Webform 6.x
Get files as email attachments.
This is also used to export attachments.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
Return value
array An array containing email attachments which include an attachments 'filename', 'filemime', 'filepath', and 'filecontent'.
Overrides WebformElementAttachmentInterface::getEmailAttachments
See also
\Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessageAttachments
\Drupal\mimemail\Utility\MimeMailFormatHelper::mimeMailHtmlBody
\Drupal\smtp\Plugin\Mail\SMTPMailSystem::mail
\Drupal\swiftmailer\Plugin\Mail\SwiftMailer::attachAsMimeMail
1 call to WebformAttachmentBase::getEmailAttachments()
- WebformAttachmentBase::getExportAttachments in modules/
webform_attachment/ src/ Plugin/ WebformElement/ WebformAttachmentBase.php - Get files as export attachments.
File
- modules/
webform_attachment/ src/ Plugin/ WebformElement/ WebformAttachmentBase.php, line 253
Class
- WebformAttachmentBase
- Provides a base class for 'webform_attachment' elements.
Namespace
Drupal\webform_attachment\Plugin\WebformElementCode
public function getEmailAttachments(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (!$this->conditionsValidator
->isElementEnabled($element, $webform_submission)) {
return [];
}
/** @var \Drupal\webform_attachment\Element\WebformAttachmentInterface $attachment_element */
$attachment_element = $this
->getFormElementClassDefinition();
$file_content = $attachment_element::getFileContent($element, $webform_submission);
$file_name = $attachment_element::getFileName($element, $webform_submission);
$file_mime = $attachment_element::getFileMimeType($element, $webform_submission);
$file_url = $attachment_element::getFileUrl($element, $webform_submission);
$attachments = [];
if ($file_name && $file_content && $file_mime) {
$attachments[] = [
'filecontent' => $file_content,
'filename' => $file_name,
'filemime' => $file_mime,
// URI is used when debugging or resending messages.
// @see \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::buildAttachments
'_fileurl' => $file_url ? $file_url
->toString() : NULL,
];
}
return $attachments;
}