1 views_handler_field_field.inc views_handler_field_field::add_self_tokens(&$tokens, $item)

Add any special tokens this field might use for itself.

This method is intended to be overridden by items that generate fields as a list. For example, the field that displays all terms on a node might have tokens for the tid and the term.

By convention, tokens should follow the format of [token-subtoken] where token is the field ID and subtoken is the field. If the field ID is terms, then the tokens might be [terms-tid] and [terms-name].

Overrides views_handler_field::add_self_tokens

File

core/modules/field/views/views_handler_field_field.inc, line 942
Definition of views_handler_field_field.

Class

views_handler_field_field
A field that displays fieldapi fields.

Code

function add_self_tokens(&$tokens, $item) {
  $field = $this->field_info;
  foreach ($field['columns'] as $id => $column) {
    // Use filter_xss_admin because it's user data and we can't be sure it is safe.
    // We know nothing about the data, though, so we can't really do much else.

    if (isset($item['raw'])) {
      // If $item['raw'] is an array then we can use as is, if it's an object
      // we cast it to an array, if it's neither, we can't use it.
      $raw = is_array($item['raw']) ? $item['raw'] :
        (is_object($item['raw']) ? (array) $item['raw'] : NULL);
    }
    if (isset($raw) && isset($raw[$id]) && is_scalar($raw[$id])) {
      $tokens['[' . $this->options['id'] . '-' . $id . ']'] = filter_xss_admin($raw[$id]);
    }
    else {
      // Take sure that empty values are replaced as well.
      $tokens['[' . $this->options['id'] . '-' . $id . ']'] = '';
    }
  }
}