You are here

public static function AutoUsernameSettingsForm::autoUsernamePunctuationChars in Automatic User Names 8

Return an array of arrays for punctuation values.

Returns an array of arrays for punctuation values keyed by a name, including the value and a textual description. Can and should be expanded to include "all" non text punctuation values.

Return value

array An array of arrays for punctuation values keyed by a name, including the value and a textual description.

4 calls to AutoUsernameSettingsForm::autoUsernamePunctuationChars()
AutoUsernameSettingsForm::autoUsernameCleanstring in src/Form/AutoUsernameSettingsForm.php
Clean up a string segment to be used in a username.
AutoUsernameSettingsForm::buildForm in src/Form/AutoUsernameSettingsForm.php
Form constructor.
AutoUsernameSettingsForm::submitForm in src/Form/AutoUsernameSettingsForm.php
Form submission handler.
AutoUsernameSettingsForm::validateForm in src/Form/AutoUsernameSettingsForm.php
Validate auto_username_settings_form form submissions.

File

src/Form/AutoUsernameSettingsForm.php, line 328

Class

AutoUsernameSettingsForm
Class AutoUsernameSettingsForm.

Namespace

Drupal\auto_username\Form

Code

public static function autoUsernamePunctuationChars() {
  $punctuation =& drupal_static(__FUNCTION__);
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  if (!isset($punctuation)) {
    $cid = 'auto_username:punctuation:' . $language;
    if ($cache = \Drupal::cache()
      ->get($cid)) {
      $punctuation = $cache->data;
    }
    else {
      $punctuation = [];
      $punctuation['double_quotes'] = [
        'value' => '"',
        'name' => t('Double quotation marks'),
      ];
      $punctuation['quotes'] = [
        'value' => '\'',
        'name' => t("Single quotation marks (apostrophe)"),
      ];
      $punctuation['backtick'] = [
        'value' => '`',
        'name' => t('Back tick'),
      ];
      $punctuation['comma'] = [
        'value' => ',',
        'name' => t('Comma'),
      ];
      $punctuation['period'] = [
        'value' => '.',
        'name' => t('Period'),
      ];
      $punctuation['hyphen'] = [
        'value' => '-',
        'name' => t('Hyphen'),
      ];
      $punctuation['underscore'] = [
        'value' => '_',
        'name' => t('Underscore'),
      ];
      $punctuation['colon'] = [
        'value' => ':',
        'name' => t('Colon'),
      ];
      $punctuation['semicolon'] = [
        'value' => ';',
        'name' => t('Semicolon'),
      ];
      $punctuation['pipe'] = [
        'value' => '|',
        'name' => t('Vertical bar (pipe)'),
      ];
      $punctuation['left_curly'] = [
        'value' => '{',
        'name' => t('Left curly bracket'),
      ];
      $punctuation['left_square'] = [
        'value' => '[',
        'name' => t('Left square bracket'),
      ];
      $punctuation['right_curly'] = [
        'value' => '}',
        'name' => t('Right curly bracket'),
      ];
      $punctuation['right_square'] = [
        'value' => ']',
        'name' => t('Right square bracket'),
      ];
      $punctuation['plus'] = [
        'value' => '+',
        'name' => t('Plus sign'),
      ];
      $punctuation['equal'] = [
        'value' => '=',
        'name' => t('Equal sign'),
      ];
      $punctuation['asterisk'] = [
        'value' => '*',
        'name' => t('Asterisk'),
      ];
      $punctuation['ampersand'] = [
        'value' => '&',
        'name' => t('Ampersand'),
      ];
      $punctuation['percent'] = [
        'value' => '%',
        'name' => t('Percent sign'),
      ];
      $punctuation['caret'] = [
        'value' => '^',
        'name' => t('Caret'),
      ];
      $punctuation['dollar'] = [
        'value' => '$',
        'name' => t('Dollar sign'),
      ];
      $punctuation['hash'] = [
        'value' => '#',
        'name' => t('Number sign (pound sign, hash)'),
      ];
      $punctuation['at'] = [
        'value' => '@',
        'name' => t('At sign'),
      ];
      $punctuation['exclamation'] = [
        'value' => '!',
        'name' => t('Exclamation mark'),
      ];
      $punctuation['tilde'] = [
        'value' => '~',
        'name' => t('Tilde'),
      ];
      $punctuation['left_parenthesis'] = [
        'value' => '(',
        'name' => t('Left parenthesis'),
      ];
      $punctuation['right_parenthesis'] = [
        'value' => ')',
        'name' => t('Right parenthesis'),
      ];
      $punctuation['question_mark'] = [
        'value' => '?',
        'name' => t('Question mark'),
      ];
      $punctuation['less_than'] = [
        'value' => '<',
        'name' => t('Less-than sign'),
      ];
      $punctuation['greater_than'] = [
        'value' => '>',
        'name' => t('Greater-than sign'),
      ];
      $punctuation['slash'] = [
        'value' => '/',
        'name' => t('Slash'),
      ];
      $punctuation['back_slash'] = [
        'value' => '\\',
        'name' => t('Backslash'),
      ];

      // Allow modules to alter the punctuation list and cache the result.
      \Drupal::moduleHandler()
        ->alter('autoUsernamePunctuationChars', $punctuation);
      \Drupal::cache()
        ->set($cid, $punctuation);
    }
  }
  return $punctuation;
}