You are here

function token_pre_render_field_token in Token 7

Pre-render callback for field output used with tokens.

1 string reference to 'token_pre_render_field_token'
field_tokens in ./token.tokens.inc
Implements hook_tokens() on behalf of field.module.

File

./token.tokens.inc, line 1439
Token callbacks for the token module.

Code

function token_pre_render_field_token($elements) {

  // Remove the field theme hook, attachments, and JavaScript states.
  unset($elements['#theme']);
  unset($elements['#states']);
  unset($elements['#attached']);

  // Prevent multi-value fields from appearing smooshed together by appending
  // a join suffix to all but the last value.
  $deltas = element_get_visible_children($elements);
  $count = count($deltas);
  if ($count > 1) {
    $join = isset($elements['#token_options']['join']) ? $elements['#token_options']['join'] : ", ";
    foreach ($deltas as $index => $delta) {

      // Do not add a suffix to the last item.
      if ($index < $count - 1) {
        $elements[$delta] += array(
          '#suffix' => $join,
        );
      }
    }
  }
  return $elements;
}