Skip to content

Commit

Permalink
fix: configure csv writer's escape character to be an empty string by…
Browse files Browse the repository at this point in the history
… default (#375)

* fix: configure csv writer's escape character to be an empty string by default

* feat: csv escape character should be configurable

---------

Co-authored-by: Irina Balaban <irina.balaban.dev@gmail.com>
  • Loading branch information
slri and Irina Balaban authored Mar 8, 2023
1 parent 5052c08 commit 241bc2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('delimiter', TextType::class)
->add('enclosure', TextType::class);
->add('enclosure', TextType::class)
->add('escape', TextType::class, ['empty_data' => '']);
}
}
6 changes: 6 additions & 0 deletions src/DataDefinitionsBundle/Provider/CsvProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public function exportData(array $configuration, ExportDefinitionInterface $defi
$writer = Writer::createFromPath($file, 'w+');
$writer->setDelimiter($configuration['delimiter']);
$writer->setEnclosure($configuration['enclosure']);
if (isset($configuration['escape'])) {
$writer->setEscape($configuration['escape']);
}
$writer->insertOne($headers);
$writer->insertAll($this->exportData);
}
Expand All @@ -161,6 +164,9 @@ public function provideArtifactStream(array $configuration, ExportDefinitionInte
$writer = Writer::createFromStream($stream);
$writer->setDelimiter($configuration['delimiter']);
$writer->setEnclosure($configuration['enclosure']);
if (isset($configuration['escape'])) {
$writer->setEscape($configuration['escape']);
}
$writer->insertOne($headers);
$writer->insertAll($this->exportData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pimcore.plugin.datadefinitions.export_provider.csv = Class.create(pimcore.plugin
fieldLabel: t('data_definitions_csv_enclosure'),
anchor: '100%',
value: this.data['enclosure'] ? this.data.enclosure : '"'
}, {
xtype: 'textfield',
name: 'escape',
fieldLabel: t('data_definitions_csv_escape'),
anchor: '100%',
maxLength: 1,
value: this.data['escape'] || '' === this.data['escape'] ? this.data.escape : '\\'
}];
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ data_definitions_provider_settings: 'Provider Settings'
data_definitions_loader: 'Loader'
data_definitions_csv_example: 'CSV Example'
data_definitions_csv_enclosure: 'Enclosure'
data_definitions_csv_escape: 'Escape'
data_definitions_csv_delimiter: 'Delimiter'
data_definitions_excel_headers: 'Excel headers'
data_definitions_excel_file: 'Excel example file'
Expand Down

0 comments on commit 241bc2a

Please sign in to comment.