You are here

public function ContactStorageDownloadForm::buildForm in Contact Storage Export 8

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/ContactStorageDownloadForm.php, line 28

Class

ContactStorageDownloadForm
Class ContactStorageDownloadForm.

Namespace

Drupal\contact_storage_export\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $contact_form = '', $key = 0) {
  $form['contact_form'] = [
    '#type' => 'hidden',
    '#value' => $contact_form,
  ];
  $form['key'] = [
    '#type' => 'hidden',
    '#value' => $key,
  ];
  if ($contact_form) {
    $form['intro'] = [
      '#type' => 'item',
      '#plain_text' => $this
        ->t('Your export is ready for download.'),
    ];
    $form['download_container'] = [
      '#type' => 'container',
    ];
    $form['download_container']['download'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Download'),
      '#attributes' => [
        'class' => [
          'button',
          'button--primary',
        ],
      ],
    ];
    $form['return'] = [
      '#title' => $this
        ->t('Return to the export page.'),
      '#type' => 'link',
      '#url' => Url::fromRoute('entity.contact_form.export_form'),
    ];
  }
  else {
    $message = $this
      ->t('An unknown error occurred preparing your download.');
    $messenger = \Drupal::messenger();
    $messenger
      ->addWarning($message, FALSE);
  }
  return $form;
}