You are here

public function WebformManagedFileBase::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

1 method overrides WebformManagedFileBase::getAttachments()
WebformImageFile::getAttachments in src/Plugin/WebformElement/WebformImageFile.php
Get email attachments.

File

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

Class

WebformManagedFileBase
Provides a base class webform 'managed_file' elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getAttachments(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' => \Drupal::service('file_system')
        ->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;
}