You are here

protected function TextBase::getInputMasks in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/TextBase.php \Drupal\webform\Plugin\WebformElement\TextBase::getInputMasks()

Get input masks.

Return value

array An associative array keyed my input mask contain input mask title, example, and patterh.

2 calls to TextBase::getInputMasks()
TextBase::getInputMaskOptions in src/Plugin/WebformElement/TextBase.php
Get input masks as select menu options.
TextBase::prepare in src/Plugin/WebformElement/TextBase.php
Prepare an element to be rendered within a webform.

File

src/Plugin/WebformElement/TextBase.php, line 358

Class

TextBase
Provides a base 'text' (field) class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function getInputMasks() {
  $input_masks = [
    "'alias': 'currency'" => [
      'title' => $this
        ->t('Currency (+)'),
      'example' => '$ 9.99',
      'pattern' => '^\\$ [0-9]{1,3}(,[0-9]{3})*.\\d\\d$',
    ],
    "'alias': 'currency_negative'" => [
      'title' => $this
        ->t('Currency (-)'),
      'example' => '-$ 9.99',
      'pattern' => '^(-\\$ [0-9]{1,3}(,[0-9]{3})*.\\d\\d|\\$ 0.00)$',
    ],
    "'alias': 'currency_positive_negative'" => [
      'title' => $this
        ->t('Currency (+/-)'),
      'example' => '$ 9.99',
      'pattern' => '^[-]?\\$ [0-9]{1,3}(,[0-9]{3})*.\\d\\d$',
    ],
    "'alias': 'datetime'" => [
      'title' => $this
        ->t('Date'),
      'example' => '2007-06-09\'T\'17:46:21',
    ],
    "'alias': 'decimal'" => [
      'title' => $this
        ->t('Decimal'),
      'example' => '1.234',
      'pattern' => '^\\d+(\\.\\d+)?$',
    ],
    "'alias': 'email'" => [
      'title' => $this
        ->t('Email'),
      'example' => 'example@example.com',
    ],
    "'alias': 'ip'" => [
      'title' => $this
        ->t('IP address'),
      'example' => '255.255.255.255',
      'pattern' => '^\\d\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d\\.\\d\\d\\d$',
    ],
    '[9-]AAA-999' => [
      'title' => $this
        ->t('License plate'),
      'example' => '[9-]AAA-999',
    ],
    "'alias': 'mac'" => [
      'title' => $this
        ->t('MAC address'),
      'example' => '99-99-99-99-99-99',
      'pattern' => '^\\d\\d-\\d\\d-\\d\\d-\\d\\d-\\d\\d-\\d\\d$',
    ],
    "'alias': 'percentage'" => [
      'title' => $this
        ->t('Percentage'),
      'example' => '99 %',
      'pattern' => '^\\d+ %$',
    ],
    '(999) 999-9999' => [
      'title' => $this
        ->t('Phone'),
      'example' => '(999) 999-9999',
      'pattern' => '^\\(\\d\\d\\d\\) \\d\\d\\d-\\d\\d\\d\\d$',
    ],
    '999-99-9999' => [
      'title' => $this
        ->t('Social Security Number (SSN)'),
      'example' => '999-99-9999',
      'pattern' => '^\\d\\d\\d-\\d\\d-\\d\\d\\d\\d$',
    ],
    "'alias': 'vin'" => [
      'title' => $this
        ->t('Vehicle identification number (VIN)'),
      'example' => 'JA3AY11A82U020534',
    ],
    '99999[-9999]' => [
      'title' => $this
        ->t('ZIP Code'),
      'example' => '99999[-9999]',
      'pattern' => '^\\d\\d\\d\\d\\d(-\\d\\d\\d\\d)?$',
    ],
    "'casing': 'upper'" => [
      'title' => $this
        ->t('Uppercase'),
      'example' => 'UPPERCASE',
    ],
    "'casing': 'lower'" => [
      'title' => $this
        ->t('Lowercase'),
      'example' => 'lowercase',
    ],
  ];

  // Get input masks.
  $modules = $this->moduleHandler
    ->getImplementations('webform_element_input_masks');
  foreach ($modules as $module) {
    $input_masks += $this->moduleHandler
      ->invoke($module, 'webform_element_input_masks');
  }

  // Alter input masks.
  $this->moduleHandler
    ->alter('webform_element_input_masks', $input_masks);
  return $input_masks;
}