You are here

function subscriptions_tokens_alter in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 7 subscriptions.tokens.inc \subscriptions_tokens_alter()

Implements hook_tokens_alter().

Add missing file tokens.

File

./subscriptions.tokens.old.php, 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;
      }
    }
  }
}