You are here

function _custom_formatters_token_replace in Custom Formatters 6

1 call to _custom_formatters_token_replace()
theme_custom_formatters_formatter in ./custom_formatters.module
2 string references to '_custom_formatters_token_replace'
custom_formatters_preprocess_custom_formatters_export_info in ./custom_formatters.admin.inc
custom_formatters_preprocess_custom_formatters_export_module in ./custom_formatters.admin.inc

File

./custom_formatters.module, line 452
Contains core functions for the Custom Formatters module.

Code

function _custom_formatters_token_replace($formatter, $element) {
  $tokens = array();

  // Prevents weird Display Suite issue.
  $element['#node'] = clone $element['#node'];

  // Prevents recursion issue.
  unset($element['#node']->content);
  $full = token_get_values('node', $element['#node']);
  $node_tokens = node_token_values('node', $element['#node']);

  // Prepend node tokens with 'node-' to prevent namespace conflicts.
  foreach ($node_tokens as $token => $value) {
    $full->tokens[array_search($token, $full->tokens)] = 'node-' . $token;
  }
  foreach (_custom_formatters_tokens_list(implode(unserialize($formatter->field_types))) as $module) {

    // Invoke hook_token_values().
    if (function_exists($function = "{$module}_token_values")) {
      $tokens = array_merge($tokens, $function('field', array(
        $element['#item'],
      )));
    }
  }
  $full->tokens = array_merge($full->tokens, array_keys($tokens));
  $full->values = array_merge($full->values, array_values($tokens));
  $tokens = token_prepare_tokens($full->tokens);
  return str_replace($tokens, $full->values, $formatter->code);
}