You are here

function courier_tokens in Courier 8

Same name and namespace in other branches
  1. 2.x courier.tokens.inc \courier_tokens()

Implements hook_tokens().

File

./courier.tokens.inc, line 32
Builds tokens for Courier.

Code

function courier_tokens($type, $tokens, array $data = [], array $options = []) {
  $replacements = [];
  if ($type == 'identity' && !empty($data['identity'])) {
    if (($identity = $data['identity']) && $identity instanceof EntityInterface) {
      foreach ($tokens as $name => $original) {
        switch ($name) {
          case 'label':
            $replacements[$original] = $identity
              ->label() ?: t('Unassigned');
            break;
        }
      }
    }
  }
  return $replacements;
}