public function TextBase::prepare in YAML Form 8
Prepare an element to be rendered within a form.
Parameters
array $element: An element.
\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.
Overrides YamlFormElementBase::prepare
1 call to TextBase::prepare()
- TextField::prepare in src/
Plugin/ YamlFormElement/ TextField.php - Prepare an element to be rendered within a form.
1 method overrides TextBase::prepare()
- TextField::prepare in src/
Plugin/ YamlFormElement/ TextField.php - Prepare an element to be rendered within a form.
File
- src/
Plugin/ YamlFormElement/ TextBase.php, line 30
Class
- TextBase
- Provides a base 'text' (field) class.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
parent::prepare($element, $yamlform_submission);
// Counter.
if (!empty($element['#counter_type']) && !empty($element['#counter_maximum'])) {
$element['#attributes']['data-counter-type'] = $element['#counter_type'];
$element['#attributes']['data-counter-limit'] = $element['#counter_maximum'];
if (!empty($element['#counter_message'])) {
$element['#attributes']['data-counter-message'] = $element['#counter_message'];
}
$element['#attributes']['class'][] = 'js-yamlform-counter';
$element['#attributes']['class'][] = 'yamlform-counter';
$element['#attached']['library'][] = 'yamlform/yamlform.element.counter';
$element['#element_validate'][] = [
get_class($this),
'validateCounter',
];
}
// Input mask.
if (!empty($element['#input_mask'])) {
// See if the element mask is JSON by looking for 'name':, else assume it
// is a mask pattern.
$input_mask = $element['#input_mask'];
if (preg_match("/^'[^']+'\\s*:/", $input_mask)) {
$element['#attributes']['data-inputmask'] = $input_mask;
}
else {
$element['#attributes']['data-inputmask-mask'] = $input_mask;
}
$element['#attributes']['class'][] = 'js-yamlform-element-mask';
$element['#attached']['library'][] = 'yamlform/yamlform.element.inputmask';
}
}