You are here

public static function PetHelper::getSubstitutions in Previewable email templates 8.3

Get token substitutions for given user or node context.

Parameters

array $context: Context items to be used for token substitutions. E.g.: [ 'uid' => NULL, 'nid' => 4, ]

'uid' will always be set when preparing data, either the user id matching recipient address, or '0' in case of no match.

Return value

array List of substitutions.

2 calls to PetHelper::getSubstitutions()
PetPreviewForm::makePreview in src/Form/PetPreviewForm.php
Generate a preview of the tokenized email for the first in the list.
pet_mail in ./pet.module
Implements hook_mail().

File

src/Utility/PetHelper.php, line 32

Class

PetHelper
PetHelper.

Namespace

Drupal\pet\Utility

Code

public static function getSubstitutions(array $context) {

  // Standard substitutions.
  $substitutions['global'] = NULL;
  if (isset($context['uid'])) {
    $user = User::load($context['uid']);
    $substitutions['user'] = $user;
  }
  if (isset($context['nid'])) {
    $node = Node::load($context['nid']);
    $substitutions['node'] = $node;
  }

  // Give modules the opportunity to add their own token types/objects.
  \Drupal::moduleHandler()
    ->alter('pet_substitutions', $substitutions);
  return $substitutions;
}