protected function WebformSubmissionExportImportUploadForm::buildUploadForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_submission_export_import/src/Form/WebformSubmissionExportImportUploadForm.php \Drupal\webform_submission_export_import\Form\WebformSubmissionExportImportUploadForm::buildUploadForm()
Build upload form.
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 An associative array containing the structure of the form.
1 call to WebformSubmissionExportImportUploadForm::buildUploadForm()
- WebformSubmissionExportImportUploadForm::buildForm in modules/
webform_submission_export_import/ src/ Form/ WebformSubmissionExportImportUploadForm.php - Form constructor.
File
- modules/
webform_submission_export_import/ src/ Form/ WebformSubmissionExportImportUploadForm.php, line 131
Class
- WebformSubmissionExportImportUploadForm
- Upload webform submission export import CSV.
Namespace
Drupal\webform_submission_export_import\FormCode
protected function buildUploadForm(array $form, FormStateInterface $form_state) {
// Warning.
$form['experimental_warning'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_id' => 'webform_submission_export_import_experimental',
'#message_close' => TRUE,
'#message_storage' => WebformMessage::STORAGE_STATE,
'#message_message' => $this
->t('Importing submissions is a new and experimental feature.') . '<br/><strong>' . $this
->t('Please test and review your imported submissions using a development/test server.') . '</strong>',
];
// Details.
$temporary_maximum_age = $this
->config('system.file')
->get('temporary_maximum_age');
$form['details'] = [
'title' => [
'#markup' => $this
->t('Please note'),
],
'list' => [
'#theme' => 'item_list',
'#items' => [
$this
->t('All submission properties and data is optional.'),
$this
->t('If UUIDs are included, existing submissions will always be updated.'),
$this
->t('If UUIDs are not included, already imported and unchanged records will not create duplication submissions.'),
$this
->t('File uploads must use publicly access URLs which begin with http:// or https://.'),
$this
->t('Entity references can use UUIDs or entity IDs.'),
$this
->t('Composite (single) values are annotated using double underscores. (e.g. ELEMENT_KEY__SUB_ELEMENT_KEY)'),
$this
->t('Multiple values are comma delimited with any nested commas URI escaped (%2C).'),
$this
->t('Multiple composite values are formatted using <a href=":href">inline YAML</a>.', [
':href' => 'https://en.wikipedia.org/wiki/YAML#Basic_components',
]),
$this
->t('Import maximum execution time limit is @time.', [
'@time' => $this->dateFormatter
->formatInterval($temporary_maximum_age),
]),
],
],
];
// Examples.
$download_url = $this->requestHandler
->getCurrentWebformUrl('webform_submission_export_import.results_import.example.download');
$view_url = $this->requestHandler
->getCurrentWebformUrl('webform_submission_export_import.results_import.example.view');
$t_args = [
':href_download' => $download_url
->toString(),
':href_view' => $view_url
->toString(),
];
$form['examples'] = [
'#markup' => $this
->t('<a href=":href_view">View</a> or <a href=":href_download">download</a> an example submission CSV.', $t_args),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
// Form.
$form['import'] = [
'#type' => 'details',
'#title' => $this
->t('Import data source'),
'#open' => TRUE,
];
$form['import']['import_type'] = [
'#title' => 'Type',
'#type' => 'radios',
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
'#options' => [
'file' => $this
->t('File upload'),
'url' => $this
->t('Remote URL'),
],
'#default_value' => 'file',
];
$form['import']['import_file'] = [
'#type' => 'file',
'#title' => $this
->t('Upload Submission CSV file'),
'#states' => [
'visible' => [
':input[name="import_type"]' => [
'value' => 'file',
],
],
'required' => [
':input[name="import_type"]' => [
'value' => 'file',
],
],
],
];
$form['import']['import_url'] = [
'#type' => 'url',
'#title' => $this
->t('Enter Submission CSV remote URL'),
'#description' => $this
->t('Remote URL could be a <a href=":href">published Google Sheet</a>.', [
':href' => 'https://help.aftership.com/hc/en-us/articles/115008490908-CSV-Auto-Fetch-using-Google-Drive-Spreadsheet',
]),
'#states' => [
'visible' => [
':input[name="import_type"]' => [
'value' => 'url',
],
],
'required' => [
':input[name="import_type"]' => [
'value' => 'url',
],
],
],
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Continue'),
'#validate' => [
'::validateUploadForm',
],
'#submit' => [
'::submitUploadForm',
],
];
return $form;
}