You are here

public function WebformResultsExportForm::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformResultsExportForm.php \Drupal\webform\Form\WebformResultsExportForm::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/WebformResultsExportForm.php, line 40

Class

WebformResultsExportForm
Webform for webform results export webform.

Namespace

Drupal\webform\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Set the merged default (global setting), saved, and user export options
  // into the webform's state.
  $settings_options = $this
    ->config('webform.settings')
    ->get('export');
  $saved_options = $this->submissionExporter
    ->getWebformOptions();
  $user_options = $this->submissionExporter
    ->getValuesFromInput($form_state
    ->getUserInput());
  $export_options = $user_options + $saved_options + $settings_options;

  // Build the webform.
  $this->submissionExporter
    ->buildExportOptionsForm($form, $form_state, $export_options);

  // Build actions.
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Download'),
    '#button_type' => 'primary',
  ];
  $form['actions']['save'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save settings'),
    '#submit' => [
      '::save',
    ],
  ];
  $form['actions']['delete'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Reset settings'),
    '#attributes' => [
      'class' => [
        'button',
        'button--danger',
      ],
    ],
    '#access' => $saved_options ? TRUE : FALSE,
    '#submit' => [
      '::delete',
    ],
  ];

  // Disable single submit.
  $form['#attributes']['class'][] = 'webform-remove-single-submit';
  $form['#attached']['library'][] = 'webform/webform.form';
  return $form;
}