You are here

class TeamInvitationNotifierEmail in Apigee Edge 8

Handles notifications for team_invitation via email.

Hierarchy

Expanded class hierarchy of TeamInvitationNotifierEmail

1 string reference to 'TeamInvitationNotifierEmail'
apigee_edge_teams.services.yml in modules/apigee_edge_teams/apigee_edge_teams.services.yml
modules/apigee_edge_teams/apigee_edge_teams.services.yml
1 service uses TeamInvitationNotifierEmail
apigee_edge_teams.team_invitation_notifier.email in modules/apigee_edge_teams/apigee_edge_teams.services.yml
Drupal\apigee_edge_teams\TeamInvitationNotifierEmail

File

modules/apigee_edge_teams/src/TeamInvitationNotifierEmail.php, line 30

Namespace

Drupal\apigee_edge_teams
View source
class TeamInvitationNotifierEmail implements TeamInvitationNotifierInterface {

  /**
   * The mail service.
   *
   * @var \Drupal\Core\Mail\MailManagerInterface
   */
  protected $mailManager;

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * TeamInvitationNotifierEmail constructor.
   *
   * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager
   *   The mail service.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   */
  public function __construct(MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) {
    $this->mailManager = $mail_manager;
    $this->languageManager = $language_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function sendNotificationsFor(TeamInvitationInterface $team_invitation) : bool {
    $email = $team_invitation
      ->getRecipient();
    $langcode = $this->languageManager
      ->getDefaultLanguage()
      ->getId();
    $params = [
      'team_invitation' => $team_invitation,
      'user' => NULL,
    ];

    /** @var \Drupal\user\UserInterface $user */
    $user = user_load_by_mail($email);
    if ($user) {
      $langcode = $user
        ->getPreferredLangcode();
      $params['user'] = $user;
    }

    // Send email notification.
    $message = $this->mailManager
      ->mail('apigee_edge_teams', 'team_invitation_created', $email, $langcode, $params);
    return $message['result'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TeamInvitationNotifierEmail::$languageManager protected property The language manager.
TeamInvitationNotifierEmail::$mailManager protected property The mail service.
TeamInvitationNotifierEmail::sendNotificationsFor public function Sends notification for the provided team_invitation. Overrides TeamInvitationNotifierInterface::sendNotificationsFor
TeamInvitationNotifierEmail::__construct public function TeamInvitationNotifierEmail constructor.