protected function NameFormatParser::generateTokens in Name Field 8
Generates the tokens from the name item.
Parameters
array $name_components: The array of name components.
Return value
array The keyed tokens generated for the given name.
1 call to NameFormatParser::generateTokens()
- NameFormatParser::format in src/
NameFormatParser.php - Formats an array of name components into the supplied format.
File
- src/
NameFormatParser.php, line 375
Class
- NameFormatParser
- Converts a name from an array of components into a defined format.
Namespace
Drupal\nameCode
protected function generateTokens(array $name_components) {
$name_components = (array) $name_components;
$name_components += [
'title' => '',
'given' => '',
'middle' => '',
'family' => '',
'credentials' => '',
'generational' => '',
'preferred' => '',
'alternative' => '',
];
$tokens = [
't' => $this
->renderComponent($name_components['title'], 'title'),
'g' => $this
->renderComponent($name_components['given'], 'given'),
'p' => $this
->renderFirstComponent([
$name_components['preferred'],
$name_components['given'],
], 'given'),
'q' => $this
->renderComponent($name_components['preferred'], 'preferred'),
'm' => $this
->renderComponent($name_components['middle'], 'middle'),
'f' => $this
->renderComponent($name_components['family'], 'family'),
'c' => $this
->renderComponent($name_components['credentials'], 'credentials'),
'a' => $this
->renderComponent($name_components['alternative'], 'alternative'),
's' => $this
->renderComponent($name_components['generational'], 'generational'),
'v' => $this
->renderComponent($name_components['preferred'], 'preferred', 'initial'),
'w' => $this
->renderFirstComponent([
$name_components['preferred'],
$name_components['given'],
], 'given', 'initial'),
'x' => $this
->renderComponent($name_components['given'], 'given', 'initial'),
'y' => $this
->renderComponent($name_components['middle'], 'middle', 'initial'),
'z' => $this
->renderComponent($name_components['family'], 'family', 'initial'),
'A' => $this
->renderComponent($name_components['alternative'], 'alternative', 'initial'),
'I' => $this
->renderComponent($name_components['given'] . ' ' . $name_components['family'], 'initials', 'initials'),
'J' => $this
->renderComponent($name_components['given'] . ' ' . $name_components['middle'] . ' ' . $name_components['family'], 'initials', 'initials'),
'K' => $this
->renderComponent($name_components['given'], 'initials', 'initials'),
'M' => $this
->renderComponent($name_components['given'] . ' ' . $name_components['middle'], 'initials', 'initials'),
'i' => $this->sep1,
'j' => $this->sep2,
'k' => $this->sep3,
];
$preferred = $tokens['p'];
$given = $tokens['g'];
$family = $tokens['f'];
if ($preferred || $family) {
$tokens += [
'd' => $preferred ? $preferred : $family,
'D' => $family ? $family : $preferred,
];
}
if ($given || $family) {
$tokens += [
'e' => $given ? $given : $family,
'E' => $family ? $family : $given,
];
}
$tokens += [
'd' => NULL,
'D' => NULL,
'e' => NULL,
'E' => NULL,
];
return $tokens;
}