public function WebformInvitationGenerateForm::buildForm in Webform Invitation 2.0.x
Same name and namespace in other branches
- 8 src/Form/WebformInvitationGenerateForm.php \Drupal\webform_invitation\Form\WebformInvitationGenerateForm::buildForm()
Form constructor.
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 The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ WebformInvitationGenerateForm.php, line 67
Class
- WebformInvitationGenerateForm
- Provides a form to generate invitation codes.
Namespace
Drupal\webform_invitation\FormCode
public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL) {
$form['webform_invitation'] = [
'#type' => 'details',
'#title' => $this
->t('Webform Invitation'),
'#open' => TRUE,
];
$form['webform_invitation']['number'] = [
'#type' => 'number',
'#title' => $this
->t('Number of codes to generate'),
'#min' => 1,
'#default_value' => 25,
'#required' => TRUE,
];
$form['webform_invitation']['type'] = [
'#type' => 'radios',
'#title' => $this
->t('Type of tokens'),
'#options' => [
'md5' => $this
->t('MD5 hash (32 characters)'),
'custom' => $this
->t('Custom'),
],
'#default_value' => 'md5',
'#required' => TRUE,
];
$form['webform_invitation']['length'] = [
'#type' => 'number',
'#title' => $this
->t('Length of tokens (number of characters)'),
'#min' => 5,
'#max' => 64,
'#default_value' => 32,
'#required' => TRUE,
'#states' => [
'invisible' => [
':input[name="type"]' => [
'value' => 'md5',
],
],
],
];
$form['webform_invitation']['chars'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Characters to be used for tokens'),
'#options' => [
1 => $this
->t('Lower case letters (a-z)'),
2 => $this
->t('Upper case letters (A-Z)'),
3 => $this
->t('Digits (0-9)'),
4 => $this
->t('Punctuation (.,:;-_!?)'),
5 => $this
->t('Special characters (#+*=$%&|)'),
],
'#default_value' => [
1,
2,
3,
],
'#required' => TRUE,
'#states' => [
'invisible' => [
':input[name="type"]' => [
'value' => 'md5',
],
],
],
];
$form['webform'] = [
'#type' => 'value',
'#value' => $webform,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Generate'),
'#button_type' => 'primary',
];
return $form;
}