Skip to content

Commit

Permalink
Make default format options in ImportExportBehaviour configurable (#4…
Browse files Browse the repository at this point in the history
…200)

Credit to @alxy.

If the default format mode is selected, there is no chance to configure the format options for delimiter, enclosure, escape and encoding. This considers a new config file item `defaultFormatOptions` and falls back to `null` if it is not specified.

To keep things consistent, the old default values remain untouched.
  • Loading branch information
alxy authored and LukeTowers committed Apr 1, 2019
1 parent dadb3e2 commit b3eb95b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions modules/backend/behaviors/ImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ public function exportFromList($definition = null, $options = [])
*/
$defaultOptions = [
'fileName' => $this->exportFileName,
'delimiter' => ',',
'enclosure' => '"'
'delimiter' => $this->getConfig('defaultFormatOptions[delimiter]', ','),
'enclosure' => $this->getConfig('defaultFormatOptions[enclosure]', '"'),
'escape' => $this->getConfig('defaultFormatOptions[escape]', '\\'),
];

$options = array_merge($defaultOptions, $options);
Expand All @@ -615,6 +616,7 @@ public function exportFromList($definition = null, $options = [])
$csv = CsvWriter::createFromFileObject(new SplTempFileObject);
$csv->setDelimiter($options['delimiter']);
$csv->setEnclosure($options['enclosure']);
$csv->setEscape($options['escape']);

/*
* Add headers
Expand Down Expand Up @@ -815,10 +817,10 @@ protected function getFormatOptionsFromPost()
$presetMode = post('format_preset');

$options = [
'delimiter' => null,
'enclosure' => null,
'escape' => null,
'encoding' => null
'delimiter' => $this->getConfig('defaultFormatOptions[delimiter]'),
'enclosure' => $this->getConfig('defaultFormatOptions[enclosure]'),
'escape' => $this->getConfig('defaultFormatOptions[escape]'),
'encoding' => $this->getConfig('defaultFormatOptions[encoding]'),
];

if ($presetMode == 'custom') {
Expand Down

0 comments on commit b3eb95b

Please sign in to comment.