WebformSubmissionExportImportWebformExporter.php in Webform 8.5
File
modules/webform_submission_export_import/src/Plugin/WebformExporter/WebformSubmissionExportImportWebformExporter.php
View source
<?php
namespace Drupal\webform_submission_export_import\Plugin\WebformExporter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformExporter\FileHandleTraitWebformExporter;
use Drupal\webform\Plugin\WebformExporterBase;
use Drupal\webform\WebformSubmissionInterface;
class WebformSubmissionExportImportWebformExporter extends WebformExporterBase {
use FileHandleTraitWebformExporter;
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'uuid' => TRUE,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['warning'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('<strong>Warning:</strong> Opening delimited text files with spreadsheet applications may expose you to <a href=":href">formula injection</a> or other security vulnerabilities. When the submissions contain data from untrusted users and the downloaded file will be used with Microsoft Excel, use \'HTML table\' format.', [
':href' => 'https://www.google.com/search?q=spreadsheet+formula+injection',
]),
];
$form['uuid'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use UUIDs for all entity references'),
'#description' => $this
->t("If checked, all entity references will use the entity's UUID"),
'#return_value' => TRUE,
'#default_value' => $this->configuration['uuid'],
];
return $form;
}
public function getFileExtension() {
return 'csv';
}
public function writeHeader() {
$header = $this
->getImporter()
->exportHeader();
fputcsv($this->fileHandle, $header);
}
public function writeSubmission(WebformSubmissionInterface $webform_submission) {
$record = $this
->getImporter()
->exportSubmission($webform_submission, $this->configuration);
fputcsv($this->fileHandle, $record);
}
protected function getImporter() {
$importer = \Drupal::service('webform_submission_export_import.importer');
$importer
->setWebform($this
->getWebform());
return $importer;
}
}