You are here

protected function EmailWebformHandler::getMessageAttachments in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformHandler/EmailWebformHandler.php \Drupal\webform\Plugin\WebformHandler\EmailWebformHandler::getMessageAttachments()

Get message file attachments.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

Return value

array A array of file attachments.

1 call to EmailWebformHandler::getMessageAttachments()
EmailWebformHandler::getMessage in src/Plugin/WebformHandler/EmailWebformHandler.php
Get a fully populated email for a webform submission.

File

src/Plugin/WebformHandler/EmailWebformHandler.php, line 1079

Class

EmailWebformHandler
Emails a webform submission.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

protected function getMessageAttachments(WebformSubmissionInterface $webform_submission) {
  if (empty($this->configuration['attachments']) || !$this
    ->supportsAttachments()) {
    return [];
  }
  $attachments = [];
  $elements = $this
    ->getWebform()
    ->getElementsInitializedAndFlattened();
  $element_attachments = $this
    ->getWebform()
    ->getElementsAttachments();
  foreach ($element_attachments as $element_attachment) {

    // Check if the element attachment key is excluded and should not attach any files.
    if (isset($this->configuration['excluded_elements'][$element_attachment])) {
      continue;
    }
    $element = $elements[$element_attachment];

    /** @var \Drupal\webform\Plugin\WebformElementAttachmentInterface $element_plugin */
    $element_plugin = $this->elementManager
      ->getElementInstance($element);
    $attachments = array_merge($attachments, $element_plugin
      ->getEmailAttachments($element, $webform_submission));
  }
  return $attachments;
}