You are here

protected function Immediately::sendEmail in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  2. 8.2 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  3. 8.3 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  4. 8.4 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  5. 8.5 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  6. 8.6 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  7. 8.7 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  8. 8.8 modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  9. 10.3.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  10. 10.0.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  11. 10.1.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()
  12. 10.2.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php \Drupal\activity_send_email\Plugin\EmailFrequency\Immediately::sendEmail()

Send an email with a single notification.

Parameters

string $body_text: The text to send to the target user.

string $langcode: The langcode of the target user.

\Drupal\user\Entity\User $target: The target account to send the email to.

1 call to Immediately::sendEmail()
Immediately::processItem in modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php
Processes an activity item.

File

modules/custom/activity_send/modules/activity_send_email/src/Plugin/EmailFrequency/Immediately.php, line 50

Class

Immediately
Define a concrete class for immediate emails.

Namespace

Drupal\activity_send_email\Plugin\EmailFrequency

Code

protected function sendEmail($body_text, $langcode, User $target) {

  // Translating frequency instance in the language of the user.
  // @codingStandardsIgnoreStart
  $frequency_translated = t($this
    ->getName()
    ->getUntranslatedString(), [], [
    'langcode' => $langcode,
  ]);

  // @codingStandardsIgnoreEnd
  // Construct the render array.
  $notification = [
    '#theme' => 'directmail',
    '#notification' => $body_text,
    '#notification_settings' => t('Based on your @settings, the notification above is sent to you <strong>:frequency</strong>', [
      '@settings' => Link::fromTextAndUrl(t('email notification settings', [], [
        'langcode' => $langcode,
      ]), Url::fromRoute('entity.user.edit_form', [
        'user' => $target
          ->id(),
      ])
        ->setAbsolute())
        ->toString(),
      ':frequency' => $frequency_translated,
    ], [
      'langcode' => $langcode,
    ]),
  ];
  $params['body'] = \Drupal::service('renderer')
    ->renderRoot($notification);

  // Send the email.
  $mail_manager = \Drupal::service('plugin.manager.mail');
  $mail_manager
    ->mail('activity_send_email', 'activity_send_email', $target
    ->getEmail(), $langcode, $params, NULL, TRUE);
}