You are here

function subscriptions_tokens_alter in Subscriptions 7

Same name and namespace in other branches
  1. 2.0.x subscriptions.tokens.old.php \subscriptions_tokens_alter()

Implements hook_tokens_alter().

Add missing file tokens.

File

./subscriptions.tokens.inc, line 541
Token callbacks for the subscriptions module.

Code

function subscriptions_tokens_alter(array &$replacements, array $context) {
  $options = $context['options'];
  $sanitize = !empty($options['sanitize']);
  $langcode = !empty($options['language']->language) ? $options['language']->language : NULL;
  if ($context['type'] == 'file' && !empty($context['data']['file'])) {
    $file = $context['data']['file'];
    foreach ($context['tokens'] as $name => $original) {
      if (isset($replacements[$original])) {
        continue;
      }
      switch ($name) {
        case 'description':
        case 'display':
        case 'title':
        case 'alt':
          if (isset($file->{$name})) {
            $value = $file->{$name};
            $replacements[$original] = $sanitize ? check_plain($value) : $value;
          }
          break;
      }
    }
  }
}