This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ginta.berzina919932
ginta.berzina919932

Hello,

has anyone tried to export backend lists which contain UTF-8 characters? For example, I have value which contains "ñ", but in export it is "& ntilde;" (without space, of course). Is there a way how to make this work without having to create custom export? It uses ImportExportController->export() function to generate report. Below configuration used:


export:
    title: Export Locations
    list: $/XXXX/YYYY/models/location/columns.yaml
    fileName: location_export.csv
    useList: true

Last updated

ginta.berzina919932
ginta.berzina919932

In case someone in future need solution for this, after carefully studying code i found solution which works (and won't be overwritten after OctoberCMS update). 1) Extend "ImportExportController" class and use it in Controller.


class XXX extend Controller
{
public $implement = [
        'Backend.Behaviors.FormController',
        'Backend.Behaviors.RelationController',
        'Backend.Behaviors.ListController',
        'AAA.BBB.Behaviors.ImportExportBehavior',
];
}


namespace AAA\BBB\Behaviors;

use Lang;
use Backend\Behaviors\ImportExportController;
use League\Csv\AbstractCsv;
use League\Csv\Writer as CsvWriter;
use SplTempFileObject;

class ImportExportBehavior extends ImportExportController
{
      .......
}

2)Copy function exportFromList and add extra line $csv->setOutputBOM(AbstractCsv::BOM_UTF8);. Example:


        /*
         * Prepare CSV
         */
        $csv = CsvWriter::createFromFileObject(new SplTempFileObject);
        $csv->setOutputBOM(AbstractCsv::BOM_UTF8);
        $csv->setDelimiter($options['delimiter']);
        $csv->setEnclosure($options['enclosure']);

3)In Plugin.php add listening for event and convert value to UTF-8 format form HTML one:


Event::listen('backend.list.overrideColumnValue', function($list, $record, $column, $value) {
            return html_entity_decode($value, ENT_QUOTES, "utf-8");
});

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.