You are here

public function WishlistShareMail::send in Commerce Wishlist 8.3

Sends the wishlist share email to the given address.

Parameters

\Drupal\commerce_wishlist\Entity\WishlistInterface $wishlist: The wishlist.

string $to: The address the email will be sent to.

Return value

bool TRUE if the email was sent successfully, FALSE otherwise.

Overrides WishlistShareMailInterface::send

File

src/Mail/WishlistShareMail.php, line 47

Class

WishlistShareMail
Defines the wishlist share email.

Namespace

Drupal\commerce_wishlist\Mail

Code

public function send(WishlistInterface $wishlist, $to) {
  $owner = $wishlist
    ->getOwner();
  if (!$owner || $owner
    ->isAnonymous()) {

    // Only wishlists belonging to authenticated users can be shared.
    return FALSE;
  }
  $subject = $this
    ->t('Check out my @site-name wishlist', [
    '@site-name' => $this->configFactory
      ->get('system.site')
      ->get('name'),
  ]);
  $body = [
    '#theme' => 'commerce_wishlist_share_mail',
    '#wishlist_entity' => $wishlist,
  ];
  $params = [
    'id' => 'wishlist_share',
    'from' => $owner
      ->getEmail(),
    'wishlist' => $wishlist,
  ];
  return $this->mailHandler
    ->sendMail($to, $subject, $body, $params);
}