You are here

function _name_generate_tokens in Name Field 7

Same name and namespace in other branches
  1. 6 includes/name.parser.inc \_name_generate_tokens()
1 call to _name_generate_tokens()
_name_format in includes/name.parser.inc
@todo Look at replacing the raw string functions with the Drupal equivalent functions. Will need to test this carefully...

File

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

Code

function _name_generate_tokens($name_components, $settings = array()) {
  $name_components = (array) $name_components;
  $markup = !empty($settings['markup']);
  $name_components += array(
    'title' => '',
    'given' => '',
    'middle' => '',
    'family' => '',
    'credentials' => '',
    'generational' => '',
    'preferred' => '',
  );
  $settings = name_settings();
  $tokens = array(
    't' => name_render_component($name_components['title'], 'title', $markup),
    'g' => name_render_component($name_components['given'], 'given', $markup),
    'q' => name_render_component($name_components['preferred'], 'preferred', $markup),
    'm' => name_render_component($name_components['middle'], 'middle', $markup),
    'f' => name_render_component($name_components['family'], 'family', $markup),
    'c' => name_render_component($name_components['credentials'], 'credentials', $markup),
    's' => name_render_component($name_components['generational'], 'generational', $markup),
    'v' => name_render_component($name_components['preferred'], 'preferred', $markup, 'initial'),
    'x' => name_render_component($name_components['given'], 'given', $markup, 'initial'),
    'y' => name_render_component($name_components['middle'], 'middle', $markup, 'initial'),
    'z' => name_render_component($name_components['family'], 'family', $markup, 'initial'),
    'i' => $settings['sep1'],
    'j' => $settings['sep2'],
    'k' => $settings['sep3'],
  );
  $given = $tokens['g'];
  $preferred = $tokens['q'];
  $family = $tokens['f'];
  $tokens += array(
    'p' => $preferred ? $preferred : $given,
    'w' => $tokens['v'] ? $tokens['v'] : $tokens['x'],
  );
  $preferred_first = $preferred ? $preferred : $given;
  if ($preferred_first || $family) {
    $tokens += array(
      'd' => $preferred_first ? $preferred_first : $family,
      'D' => $family ? $family : $preferred_first,
    );
  }
  else {
    $tokens += array(
      'd' => NULL,
      'D' => NULL,
    );
  }
  if ($given || $family) {
    $tokens += array(
      'e' => $given ? $given : $family,
      'E' => $family ? $family : $given,
    );
  }
  else {
    $tokens += array(
      'e' => NULL,
      'E' => NULL,
    );
  }
  return $tokens;
}