You are here

class WishlistShareMail in Commerce Wishlist 8.3

Defines the wishlist share email.

Hierarchy

Expanded class hierarchy of WishlistShareMail

1 string reference to 'WishlistShareMail'
commerce_wishlist.services.yml in ./commerce_wishlist.services.yml
commerce_wishlist.services.yml
1 service uses WishlistShareMail
commerce_wishlist.wishlist_share_mail in ./commerce_wishlist.services.yml
Drupal\commerce_wishlist\Mail\WishlistShareMail

File

src/Mail/WishlistShareMail.php, line 13

Namespace

Drupal\commerce_wishlist\Mail
View source
class WishlistShareMail implements WishlistShareMailInterface {
  use StringTranslationTrait;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The commerce mail handler.
   *
   * @var \Drupal\commerce\MailHandlerInterface
   */
  protected $mailHandler;

  /**
   * Constructs a new WishlistShareMail object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   * @param \Drupal\commerce\MailHandlerInterface $mail_handler
   *   The mail handler.
   */
  public function __construct(ConfigFactoryInterface $config_factory, MailHandlerInterface $mail_handler) {
    $this->configFactory = $config_factory;
    $this->mailHandler = $mail_handler;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WishlistShareMail::$configFactory protected property The config factory.
WishlistShareMail::$mailHandler protected property The commerce mail handler.
WishlistShareMail::send public function Sends the wishlist share email to the given address. Overrides WishlistShareMailInterface::send
WishlistShareMail::__construct public function Constructs a new WishlistShareMail object.