You are here

function publication_date_tokens in Publication Date 7

Same name and namespace in other branches
  1. 8.2 publication_date.tokens.inc \publication_date_tokens()
  2. 8 publication_date.tokens.inc \publication_date_tokens()
  3. 7.2 publication_date.tokens.inc \publication_date_tokens()

Implements hook_tokens().

File

./publication_date.tokens.inc, line 22
Builds placeholder replacement tokens for node-related data.

Code

function publication_date_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
    $language_code = $options['language']->language;
  }
  else {
    $language_code = NULL;
  }
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'published':
          $replacements[$original] = format_date($node->published_at, 'medium', '', NULL, $language_code);
          break;
      }
    }
    if ($published_tokens = token_find_with_prefix($tokens, 'published')) {
      $replacements += token_generate('date', $published_tokens, array(
        'date' => $node->published_at,
      ), $options);
    }
  }
  return $replacements;
}