You are here

public function WebformInvitationForm::buildForm in Webform Invitation 8

Same name and namespace in other branches
  1. 2.0.x src/Form/WebformInvitationForm.php \Drupal\webform_invitation\Form\WebformInvitationForm::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/WebformInvitationForm.php, line 27

Class

WebformInvitationForm
Enable or disable invitations for the current webform.

Namespace

Drupal\webform_invitation\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL) {
  $elements = $webform
    ->getElementsDecodedAndFlattened();

  // Check if current webform has enabled invitations.
  $enabled = isset($elements['webform_invitation_code']);
  $form['webform_invitation'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Webform Invitation'),
    '#open' => TRUE,
  ];
  $form['webform_invitation']['enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable invitations for this webform'),
    '#default_value' => $enabled,
    '#description' => $this
      ->t('If checked, invitations will be enabled for this webform.'),
  ];
  $form['webform'] = [
    '#type' => 'value',
    '#value' => $webform,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
  ];
  return $form;
}