Make default format options in ImportExportBehaviour configurable (#4200)
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.
This commit is contained in:
parent
dadb3e2c01
commit
b3eb95bb62
|
|
@ -601,8 +601,9 @@ class ImportExportController extends ControllerBehavior
|
|||
*/
|
||||
$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);
|
||||
|
|
@ -615,6 +616,7 @@ class ImportExportController extends ControllerBehavior
|
|||
$csv = CsvWriter::createFromFileObject(new SplTempFileObject);
|
||||
$csv->setDelimiter($options['delimiter']);
|
||||
$csv->setEnclosure($options['enclosure']);
|
||||
$csv->setEscape($options['escape']);
|
||||
|
||||
/*
|
||||
* Add headers
|
||||
|
|
@ -815,10 +817,10 @@ class ImportExportController extends ControllerBehavior
|
|||
$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') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue