public function TextBase::form in YAML Form 8
Gets the actual configuration form array to be built.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An associative array contain the element's configuration form without any default values..
Overrides YamlFormElementBase::form
2 calls to TextBase::form()
- Textarea::form in src/
Plugin/ YamlFormElement/ Textarea.php - Gets the actual configuration form array to be built.
- YamlFormAutocomplete::form in src/
Plugin/ YamlFormElement/ YamlFormAutocomplete.php - Gets the actual configuration form array to be built.
2 methods override TextBase::form()
- Textarea::form in src/
Plugin/ YamlFormElement/ Textarea.php - Gets the actual configuration form array to be built.
- YamlFormAutocomplete::form in src/
Plugin/ YamlFormElement/ YamlFormAutocomplete.php - Gets the actual configuration form array to be built.
File
- src/
Plugin/ YamlFormElement/ TextBase.php, line 68
Class
- TextBase
- Provides a base 'text' (field) class.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Input mask.
$form['form']['input_mask'] = [
'#type' => 'yamlform_select_other',
'#title' => $this
->t('Input masks'),
'#description' => $this
->t('An <a href=":href">inputmask</a> helps the user with the element by ensuring a predefined format.', [
':href' => 'https://github.com/RobinHerbots/jquery.inputmask',
]),
'#other__option_label' => $this
->t('Custom...'),
'#other__placeholder' => $this
->t('Enter input mask...'),
'#other__description' => $this
->t('(9 = numeric; a = alphabetical; * = alphanumeric)'),
'#options' => [
'' => '',
'Basic' => [
"'alias': 'currency'" => $this
->t('Currency - @format', [
'@format' => '$ 9.99',
]),
"'alias': 'mm/dd/yyyy'" => $this
->t('Date - @format', [
'@format' => 'mm/dd/yyyy',
]),
"'alias': 'email'" => $this
->t('Email - @format', [
'@format' => 'example@example.com',
]),
"'alias': 'percentage'" => $this
->t('Percentage - @format', [
'@format' => '99%',
]),
'(999) 999-9999' => $this
->t('Phone - @format', [
'@format' => '(999) 999-9999',
]),
'99999[-9999]' => $this
->t('Zip code - @format', [
'@format' => '99999[-9999]',
]),
],
'Advanced' => [
"'alias': 'ip'" => 'IP address - 255.255.255.255',
'[9-]AAA-999' => 'License plate - [9-]AAA-999',
"'alias': 'mac'" => 'MAC addresses - 99-99-99-99-99-99',
'999-99-9999' => 'SSN - 999-99-9999',
"'alias': 'vin'" => 'VIN (Vehicle identification number)',
],
],
];
// Pattern.
$form['validation']['pattern'] = [
'#type' => 'textfield',
'#title' => $this
->t('Pattern'),
'#description' => $this
->t('A <a href=":href">regular expression</a> that the element\'s value is checked against.', [
':href' => 'http://www.w3schools.com/js/js_regexp.asp',
]),
];
// Counter.
$form['validation']['counter_type'] = [
'#type' => 'select',
'#title' => $this
->t('Count'),
'#description' => $this
->t('Limit entered value to a maximum number of characters or words.'),
'#options' => [
'' => '',
'character' => $this
->t('Characters'),
'word' => $this
->t('Words'),
],
];
$form['validation']['counter_maximum'] = [
'#type' => 'number',
'#title' => $this
->t('Count maximum'),
'#min' => 1,
'#states' => [
'invisible' => [
':input[name="properties[counter_type]"]' => [
'value' => '',
],
],
'optional' => [
':input[name="properties[counter_type]"]' => [
'value' => '',
],
],
],
];
$form['validation']['counter_message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Count message'),
'#description' => $this
->t('Defaults to: %value', [
'%value' => $this
->t('X characters/word(s) left'),
]),
'#states' => [
'invisible' => [
':input[name="properties[counter_type]"]' => [
'value' => '',
],
],
],
];
return $form;
}