You are here

function _name_token_values in Name Field 6

Implementation of hook_token_values().

1 call to _name_token_values()
name_token_values in ./name.module
Implementation of hook_token_values().

File

includes/name.token.inc, line 36
Provides the hooks required for Token module integration.

Code

function _name_token_values($type, $object = NULL) {
  $item = $object[0];
  $name_components = array();
  foreach (_name_translations() as $key => $title) {
    if (!empty($item[$key])) {
      $name_components[$key] = $item[$key];
    }
    else {
      $name_components[$key] = '';
    }
  }
  $default = name_format($name_components, name_settings('default_format'), array(
    'object' => $object,
    'type' => 'node',
  ));
  $tokens['raw'] = $default;
  $tokens['plain'] = strip_tags($default);
  $tokens['formatted'] = $tokens['default'] = check_plain($default);
  foreach (name_get_custom_format_options() as $machine_name => $name_title) {
    $format = name_get_format_by_machine_name($machine_name);
    $formated_name = name_format($name_components, $format, array(
      'object' => $object,
      'type' => 'node',
    ));
    $tokens['formatted-' . $machine_name] = check_plain($formated_name);
    $tokens['formatted-' . $machine_name . '-plain'] = strip_tags($formated_name);
    $tokens['formatted-' . $machine_name . '-raw'] = $formated_name;
  }
  foreach (_name_translations() as $key => $title) {
    $tokens[$key . '-raw'] = $name_components[$key];
    $tokens[$key] = $tokens[$key . '-formatted'] = check_plain($name_components[$key]);
    $tokens[$key . '-plain'] = strip_tags($name_components[$key]);
  }
  return $tokens;
}