You are here

public function NameFormatParser::tokenHelp in Name Field 8

Supported tokens.

Parameters

bool $describe: Appends the description of the letter to the description.

Return value

string[] An array of strings keyed by the token.

1 call to NameFormatParser::tokenHelp()
NameFormatParser::renderableTokenHelp in src/NameFormatParser.php
Helper function to provide name format token help.

File

src/NameFormatParser.php, line 559

Class

NameFormatParser
Converts a name from an array of components into a defined format.

Namespace

Drupal\name

Code

public function tokenHelp($describe = TRUE) {
  $tokens = [
    't' => $this
      ->t('Title.'),
    'p' => $this
      ->t('Preferred name, use given name if not set.'),
    'q' => $this
      ->t('Preferred name.'),
    'g' => $this
      ->t('Given name.'),
    'm' => $this
      ->t('Middle name(s).'),
    'f' => $this
      ->t('Family name.'),
    'c' => $this
      ->t('Credentials.'),
    's' => $this
      ->t('Generational suffix.'),
    'a' => $this
      ->t('Alternative value.'),
    'v' => $this
      ->t('First letter preferred name.'),
    'w' => $this
      ->t('First letter preferred or given name.'),
    'x' => $this
      ->t('First letter given.'),
    'y' => $this
      ->t('First letter middle.'),
    'z' => $this
      ->t('First letter family.'),
    'A' => $this
      ->t('First letter of alternative value.'),
    'I' => $this
      ->t('Initials (all) from given and family.'),
    'J' => $this
      ->t('Initials (all) from given, middle and family.'),
    'K' => $this
      ->t('Initials (all) from given.'),
    'M' => $this
      ->t('Initials (all) from given and middle.'),
    'd' => $this
      ->t('Conditional: Either the preferred given or family name. Preferred name is given preference over given or family names.'),
    'D' => $this
      ->t('Conditional: Either the preferred given or family name. Family name is given preference over preferred or given names.'),
    'e' => $this
      ->t('Conditional: Either the given or family name. Given name is given preference.'),
    'E' => $this
      ->t('Conditional: Either the given or family name. Family name is given preference.'),
    'i' => $this
      ->t('Separator 1.'),
    'j' => $this
      ->t('Separator 2.'),
    'k' => $this
      ->t('Separator 3.'),
    '\\' => $this
      ->t('You can prevent a character in the format string from being expanded by escaping it with a preceding backslash.'),
    'L' => $this
      ->t('Modifier: Converts the next token to all lowercase.'),
    'U' => $this
      ->t('Modifier: Converts the next token to all uppercase.'),
    'F' => $this
      ->t('Modifier: Converts the first letter to uppercase.'),
    'G' => $this
      ->t('Modifier: Converts the first letter of ALL words to uppercase.'),
    'T' => $this
      ->t('Modifier: Trims whitespace around the next token.'),
    'S' => $this
      ->t('Modifier: Ensures that the next token is safe for the display.'),
    'B' => $this
      ->t('Modifier: Use the first word of the next token.'),
    'b' => $this
      ->t('Modifier: Use the last word of the next token.'),
    '+' => $this
      ->t('Conditional: Insert the token if both the surrounding tokens are not empty.'),
    '-' => $this
      ->t('Conditional: Insert the token if the previous token is not empty.'),
    '~' => $this
      ->t('Conditional: Insert the token if the previous token is empty.'),
    '=' => $this
      ->t('Conditional: Insert the token if the next token is not empty.'),
    '^' => $this
      ->t('Conditional: Insert the token if the next token is empty.'),
    '|' => $this
      ->t('Conditional: Uses the previous token unless empty, otherwise it uses this token.'),
    '(' => $this
      ->t('Group: Start of token grouping.'),
    ')' => $this
      ->t('Group: End of token grouping.'),
  ];
  if ($describe) {
    foreach ($tokens as $letter => $description) {
      if (preg_match('/^[a-z]+$/', $letter)) {
        $tokens[$letter] = $this
          ->t('@description<br><small>(lowercase @letter)</small>', [
          '@description' => $description,
          '@letter' => mb_strtoupper($letter),
        ]);
      }
      elseif (preg_match('/^[A-Z]+$/', $letter)) {
        $tokens[$letter] = $this
          ->t('@description<br><small>(uppercase @letter)</small>', [
          '@description' => $description,
          '@letter' => mb_strtoupper($letter),
        ]);
      }
    }
  }
  return $tokens;
}