class DelimitedWebformExporter in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformExporter/DelimitedWebformExporter.php \Drupal\webform\Plugin\WebformExporter\DelimitedWebformExporter
Defines a delimited text exporter.
Plugin annotation
@WebformExporter(
id = "delimited",
label = @Translation("Delimited text"),
description = @Translation("Exports results as delimited text file."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\webform\Plugin\WebformExporterBase implements WebformExporterInterface uses WebformEntityStorageTrait
- class \Drupal\webform\Plugin\WebformExporter\TabularBaseWebformExporter uses FileHandleTraitWebformExporter
- class \Drupal\webform\Plugin\WebformExporter\DelimitedWebformExporter
- class \Drupal\webform\Plugin\WebformExporter\TabularBaseWebformExporter uses FileHandleTraitWebformExporter
- class \Drupal\webform\Plugin\WebformExporterBase implements WebformExporterInterface uses WebformEntityStorageTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of DelimitedWebformExporter
File
- src/
Plugin/ WebformExporter/ DelimitedWebformExporter.php, line 17
Namespace
Drupal\webform\Plugin\WebformExporterView source
class DelimitedWebformExporter extends TabularBaseWebformExporter {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'delimiter' => ',',
'excel' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
parent::setConfiguration($configuration);
$this->configuration['delimiter'] = $this->configuration['delimiter'] === '\\t' ? "\t" : $this->configuration['delimiter'];
return $this;
}
/**
* {@inheritdoc}
*/
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['delimiter'] = [
'#type' => 'select',
'#title' => $this
->t('Delimiter text format'),
'#description' => $this
->t('This is the delimiter used in the CSV/TSV file when downloading webform results. Using tabs in the export is the most reliable method for preserving non-latin characters. You may want to change this to another character depending on the program with which you anticipate importing results.'),
'#required' => TRUE,
'#options' => [
',' => $this
->t('Comma (,)'),
'\\t' => $this
->t('Tab (\\t)'),
';' => $this
->t('Semicolon (;)'),
':' => $this
->t('Colon (:)'),
'|' => $this
->t('Pipe (|)'),
'.' => $this
->t('Period (.)'),
' ' => $this
->t('Space ( )'),
],
'#default_value' => $this->configuration['delimiter'] === "\t" ? '\\t' : $this->configuration['delimiter'],
];
$form['excel'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Generate Excel compatible file'),
'#description' => $this
->t("If checked, the generated file's carriage returns will be compatible with Excel and a marker flagging the data as UTF-8 will be added at the beginning."),
'#return_value' => TRUE,
'#default_value' => $this->configuration['excel'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function getFileExtension() {
switch ($this->configuration['delimiter']) {
case "\t":
return 'tsv';
default:
return 'csv';
}
}
/**
* {@inheritdoc}
*/
public function writeHeader() {
if ($this->configuration['excel']) {
fwrite($this->fileHandle, "");
}
$header = $this
->buildHeader();
fputcsv($this->fileHandle, $header, $this->configuration['delimiter']);
}
/**
* {@inheritdoc}
*/
public function writeSubmission(WebformSubmissionInterface $webform_submission) {
$record = $this
->buildRecord($webform_submission);
fputcsv($this->fileHandle, $record, $this->configuration['delimiter']);
}
/**
* {@inheritdoc}
*/
protected function buildRecord(WebformSubmissionInterface $webform_submission) {
$record = parent::buildRecord($webform_submission);
if ($this->configuration['excel']) {
foreach ($record as $index => $value) {
if (is_string($value)) {
$record[$index] = str_replace(PHP_EOL, "\r\n", $value);
}
}
}
return $record;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DelimitedWebformExporter:: |
public | function |
Form constructor. Overrides WebformExporterBase:: |
|
DelimitedWebformExporter:: |
protected | function |
Build export record using a webform submission. Overrides TabularBaseWebformExporter:: |
|
DelimitedWebformExporter:: |
public | function |
Gets default configuration for this plugin. Overrides WebformExporterBase:: |
|
DelimitedWebformExporter:: |
public | function |
Get export file extension. Overrides WebformExporterBase:: |
|
DelimitedWebformExporter:: |
public | function |
Sets the configuration for this plugin instance. Overrides WebformExporterBase:: |
|
DelimitedWebformExporter:: |
public | function |
Write header to export. Overrides WebformExporterBase:: |
|
DelimitedWebformExporter:: |
public | function |
Write submission to export. Overrides WebformExporterBase:: |
|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileHandleTraitWebformExporter:: |
protected | property | A file handler resource. | |
FileHandleTraitWebformExporter:: |
public | function | ||
FileHandleTraitWebformExporter:: |
public | function | ||
FileHandleTraitWebformExporter:: |
public | function | ||
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TabularBaseWebformExporter:: |
protected | property | The date formatter service. | |
TabularBaseWebformExporter:: |
protected | property | An associative array containing webform elements keyed by name. | |
TabularBaseWebformExporter:: |
protected | property | An associative array containing a webform's field definitions. | |
TabularBaseWebformExporter:: |
protected | function | Build export header using webform submission field definitions and webform element columns. | 1 |
TabularBaseWebformExporter:: |
public static | function |
Creates an instance of the plugin. Overrides WebformExporterBase:: |
|
TabularBaseWebformExporter:: |
protected | function | Get the field definition value from a webform submission entity. | |
TabularBaseWebformExporter:: |
protected | function | Get webform elements. | |
TabularBaseWebformExporter:: |
protected | function | Get a webform's field definitions. | |
WebformEntityStorageTrait:: |
protected | property | An associate array of entity type storage aliases. | |
WebformEntityStorageTrait:: |
protected | property | The entity type manager. | 5 |
WebformEntityStorageTrait:: |
protected | function | Retrieves the entity storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform submission storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform storage. | |
WebformEntityStorageTrait:: |
public | function | Implements the magic __get() method. | |
WebformExporterBase:: |
protected | property | Cached archive object. | |
WebformExporterBase:: |
protected | property | The configuration factory. | |
WebformExporterBase:: |
protected | property | The webform element manager. | |
WebformExporterBase:: |
protected | property | A logger instance. | |
WebformExporterBase:: |
protected | property | The webform token manager. | |
WebformExporterBase:: |
public | function |
Add file, directory, or content to exporter archive. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Add file, directory, or content to Tar archive. | |
WebformExporterBase:: |
protected | function | Add file, directory, or content to ZIP file. | |
WebformExporterBase:: |
public | function |
Returns the results exporter description. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file extension for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file name for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file name and path for a webform. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get archive file type. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export base file name without an extension. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get the number of submissions to be exported with each batch. Overrides WebformExporterInterface:: |
1 |
WebformExporterBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file name. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file path. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get export file temp directory. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Get the webform source entity whose submissions are being exported. | |
WebformExporterBase:: |
public | function |
Returns the results exporter status. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Get webform submission base file name. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
protected | function | Get the webform whose submissions are being exported. | |
WebformExporterBase:: |
public | function |
Determine if exporter can include uploaded files (in a zipped archive). Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Determine if exporter has options. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Determine if exporter generates an archive. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Checks if the exporter is excluded via webform.settings. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Returns the results exporter label. Overrides WebformExporterInterface:: |
|
WebformExporterBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
WebformExporterBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
WebformExporterBase:: |
public | function |
Write footer to export. Overrides WebformExporterInterface:: |
1 |
WebformExporterInterface:: |
constant | Tar archive. | ||
WebformExporterInterface:: |
constant | ZIP file. |