You are here

public function WebformManagedFileBase::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 method overrides WebformManagedFileBase::getEmailAttachments()
WebformImageFile::getEmailAttachments in src/Plugin/WebformElement/WebformImageFile.php
Get files as email attachments.

File

src/Plugin/WebformElement/WebformManagedFileBase.php, line 1438

Class

WebformManagedFileBase
Provides a base class webform 'managed_file' elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getEmailAttachments(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $attachments = [];
  $files = $this
    ->getTargetEntities($element, $webform_submission, $options) ?: [];
  foreach ($files as $file) {
    $attachments[] = [
      'filecontent' => file_get_contents($file
        ->getFileUri()),
      'filename' => $file
        ->getFilename(),
      'filemime' => $file
        ->getMimeType(),
      // File URIs that are not supported return FALSE, when this happens
      // still use the file's URI as the file's path.
      'filepath' => $this->fileSystem
        ->realpath($file
        ->getFileUri()) ?: $file
        ->getFileUri(),
      // URI is used when debugging or resending messages.
      // @see \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::buildAttachments
      '_fileurl' => file_create_url($file
        ->getFileUri()),
    ];
  }
  return $attachments;
}