Commit 1c4c5b6e authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3284142 by AdamPS, nojj: Add support to attachments for LegacyEmailBuilder

parent d4761e79
Loading
Loading
Loading
Loading
+6 −0
Changes for modules/symfony_mailer_bc/src/Plugin/EmailBuilder/LegacyEmailBuilder.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -124,6 +124,12 @@ class LegacyEmailBuilder extends EmailBuilderBase implements ContainerFactoryPlu
  protected function emailFromArray(EmailInterface $email, array $message) {
    $email->setSubject($message['subject']);

    // Add attachments.
    $attachments = $message['params']['attachments'] ?? [];
    foreach ($attachments as $attachment) {
      $email->attachFromPath($attachment['filepath'], $attachment['filename'] ?? NULL, $attachment['filemime'] ?? NULL);
    }

    // Add Address headers from message array to Email object.
    // The "To" header will be set via build().
    foreach (self::HEADERS as $name => $key) {
+9 −24
Changes for src/BaseEmailInterface.php: 9 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -206,40 +206,25 @@ interface BaseEmailInterface {
   */
  public function getHtmlBody(): ?string;

  // @codingStandardsIgnoreStart
  /**
   * @param string $body
   * Adds an attachment.
   *
   * @return $this
   */
  // public function attach(string $body, string $name = null, string $contentType = null);

  /**
   * @return $this
   */
  // public function attachFromPath(string $path, string $name = null, string $contentType = null);

  /**
   * @param string $body
   * @param string $path
   *   The path to the file.
   * @param string|null $name
   *   (optional) The file name. Defaults to the base name of the path.
   * @param string|null $mimeType
   *   (optional) The mime type. If omitted, the type will be guessed.
   *
   * @return $this
   */
  // public function embed(string $body, string $name = null, string $contentType = null);
  public function attachFromPath(string $path, ?string $name = NULL, ?string $mimeType = NULL);

  // @codingStandardsIgnoreStart
  /**
   * @return $this
   */
  // public function embedFromPath(string $path, string $name = null, string $contentType = null);

  /**
   * @return $this
   */
  // public function attachPart(DataPart $part);

  /**
   * @return array|DataPart[]
   */
  // public function getAttachments(): array;
  // @codingStandardsIgnoreEnd

  /**
+8 −10
Changes for src/BaseEmailTrait.php: 8 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -180,18 +180,16 @@ trait BaseEmailTrait {
    return $this->inner->getHtmlBody();
  }

  // @codingStandardsIgnoreStart
  // public function attach(string $body, string $name = null, string $contentType = null);

  // public function attachFromPath(string $path, string $name = null, string $contentType = null);

  // public function embed(string $body, string $name = null, string $contentType = null);
  /**
   * {@inheritdoc}
   */
  public function attachFromPath(string $path, string $name = NULL, string $mimeType = NULL) {
    $this->inner->attachFromPath($path, $name, $mimeType);
    return $this;
  }

  // @codingStandardsIgnoreStart
  // public function embedFromPath(string $path, string $name = null, string $contentType = null);

  // public function attachPart(DataPart $part);

  // public function getAttachments();
  // @codingStandardsIgnoreEnd

  /**