You are here

public function MailEntity::getSubject in Simplenews 8.2

Same name and namespace in other branches
  1. 8 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getSubject()
  2. 3.x src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getSubject()

Returns the mail subject.

Return value

string The mail subject.

Overrides MailInterface::getSubject

File

src/Mail/MailEntity.php, line 218

Class

MailEntity
Default mail class for entities.

Namespace

Drupal\simplenews\Mail

Code

public function getSubject() {

  // Build email subject and perform some sanitizing.
  // Use the requested language if enabled.
  $langcode = $this
    ->getLanguage();
  $subject = \Drupal::token()
    ->replace($this
    ->getNewsletter()->subject, $this
    ->getTokenContext(), [
    'sanitize' => FALSE,
    'langcode' => $langcode,
  ]);

  // Line breaks are removed from the email subject to prevent injection of
  // malicious data into the email header.
  $subject = str_replace([
    "\r",
    "\n",
  ], '', $subject);
  return $subject;
}