public function MaskedinputFieldWidgetDefault::settingsForm in Masked Input 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form definition for the widget settings.
Overrides StringTextfieldWidget::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ MaskedinputFieldWidgetDefault.php, line 39
Class
- MaskedinputFieldWidgetDefault
- Plugin implementation of the 'masked_input_field_widget_default default' widget.
Namespace
Drupal\masked_input\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$definitions = masked_input_view_configured_definitions();
$header = array(
$this
->t('Character'),
$this
->t('Regular expression'),
$this
->t('Description'),
);
$element['size'] = array(
'#type' => 'number',
'#title' => $this
->t('Size of textfield'),
'#default_value' => $this
->getSetting('size'),
'#required' => TRUE,
'#min' => 1,
);
$element['placeholder'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Placeholder'),
'#default_value' => $this
->getSetting('placeholder'),
'#description' => $this
->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
);
$element['mask_placeholder'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Maks placeholder'),
'#default_value' => '_',
'#description' => $this
->t('Optionally, if you are not satisfied with the underscore ("_") character as a placeholder, you may pass an optional argument to the masked_input method.'),
);
$element['mask'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Mask'),
'#default_value' => $this
->getSetting('mask'),
'#description' => $this
->t('Add mask.'),
);
$url = Url::fromRoute('masked_input.settings');
$admin_link = \Drupal::l($this
->t('admin/config/user-interface/masked_input'), $url);
$caption = "A mask is defined by a format made up of mask literals and mask definitions. Any character not in the definitions list below is considered a mask literal. Mask literals will be automatically entered for the user as they type and will not be able to be removed by the user. Here is a list of definitions that already exist, you can create more at link {$admin_link}";
$element['masktable'] = array(
'#type' => 'table',
'#caption' => $this
->t($caption),
'#header' => $header,
);
foreach ($definitions as $i => $rows) {
$element['masktable'][$i]['character'] = array(
'#markup' => $rows['0']['data'],
);
$element['masktable'][$i]['rgx'] = array(
'#markup' => $rows['1']['data'],
);
$element['masktable'][$i]['dec'] = array(
'#markup' => $rows['2']['data'],
);
}
return $element;
}