You are here

protected function MailEntity::setContext in Simplenews 8

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

Set up the necessary language and user context.

1 call to MailEntity::setContext()
MailEntity::getBodyWithFormat in src/Mail/MailEntity.php
Get the body with the requested format.

File

src/Mail/MailEntity.php, line 252

Class

MailEntity
Default mail class for entities.

Namespace

Drupal\simplenews\Mail

Code

protected function setContext() {

  // Switch to the user
  if ($this->uid = $this
    ->getSubscriber()
    ->getUserId()) {
    \Drupal::service('account_switcher')
      ->switchTo(User::load($this->uid));
  }

  // Change language if the requested language is enabled.

  /*$language = $this->getLanguage();
    $languages = LanguageManagerInterface::getLanguages();
    if (isset($languages[$language])) {
      $this->original_language = \Drupal::languageManager()->getCurrentLanguage();
      $GLOBALS['language'] = $languages[$language];
      $GLOBALS['language_url'] = $languages[$language];
      // Overwrites the current content language for i18n_select.
      if (\Drupal::moduleHandler()->moduleExists('i18n_select')) {
        $GLOBALS['language_content'] = $languages[$language];
      }
    }*/
}