public function WebformAttachmentBase::getAttachments in Webform 8.5
Get email 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::getAttachments
See also
\Drupal\mimemail\Utility\MimeMailFormatHelper::mimeMailHtmlBody
\Drupal\smtp\Plugin\Mail\SMTPMailSystem::mail
\Drupal\swiftmailer\Plugin\Mail\SwiftMailer::attachAsMimeMail
File
- modules/
webform_attachment/ src/ Plugin/ WebformElement/ WebformAttachmentBase.php, line 236
Class
- WebformAttachmentBase
- Provides a base class for 'webform_attachment' elements.
Namespace
Drupal\webform_attachment\Plugin\WebformElementCode
public function getAttachments(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
/** @var \Drupal\webform\WebformSubmissionConditionsValidatorInterface $conditions_validator */
$conditions_validator = \Drupal::service('webform_submission.conditions_validator');
if (!$conditions_validator
->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;
}