You are here

function _name_generate_tokens in Name Field 6

Same name and namespace in other branches
  1. 7 includes/name.parser.inc \_name_generate_tokens()
1 call to _name_generate_tokens()
_name_format in includes/name.parser.inc

File

includes/name.parser.inc, line 78
Provides the functionality and information about the Name module name parsing engine.

Code

function _name_generate_tokens($name_components) {
  $name_components = (array) $name_components;
  $name_components += array(
    'title' => '',
    'given' => '',
    'middle' => '',
    'family' => '',
    'credentials' => '',
    'generational' => '',
  );
  $settings = name_settings();
  $tokens = array(
    't' => isset($name_components['title']) ? $name_components['title'] : NULL,
    'g' => isset($name_components['given']) ? $name_components['given'] : NULL,
    'm' => isset($name_components['middle']) ? $name_components['middle'] : NULL,
    'f' => isset($name_components['family']) ? $name_components['family'] : NULL,
    'c' => isset($name_components['credentials']) ? $name_components['credentials'] : NULL,
    's' => isset($name_components['generational']) ? $name_components['generational'] : NULL,
    'x' => isset($name_components['given']) && strlen($name_components['given']) ? $name_components['given'][0] : NULL,
    'y' => isset($name_components['middle']) && strlen($name_components['middle']) ? $name_components['middle'][0] : NULL,
    'z' => isset($name_components['family']) && strlen($name_components['family']) ? $name_components['family'][0] : NULL,
    'i' => $settings['sep1'],
    'j' => $settings['sep2'],
    'k' => $settings['sep3'],
  );
  $given = trim((string) $name_components['given']);
  $family = trim((string) $name_components['family']);
  if ($given || $family) {
    $tokens += array(
      'e' => $given ? $given : $family,
      'E' => $family ? $family : $given,
    );
  }
  else {
    $tokens += array(
      'e' => NULL,
      'E' => NULL,
    );
  }
  return $tokens;
}