Skip to content

Commit c7a9d0e

Browse files
authored
[Grid] Download localized fields wrong values (#1736)
* Add local label to export. Fix export with localized fields. * Reduce complexity. * Replace Deprecated CSV method
1 parent e5f282e commit c7a9d0e

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"minimum-stability": "dev",
1919
"require": {
2020
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
21-
"league/csv": "^9.22",
21+
"league/csv": "^9.27",
2222
"nesbot/carbon": "^3.8.4",
2323
"pimcore/static-resolver-bundle": "^3.5.0 || ^2026.1",
2424
"pimcore/generic-data-index-bundle": "^2.4.0 || ^2026.1",

src/Export/Service/CsvExportService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function generateExportFile(
4848
$data = array_merge($data, $exportData);
4949

5050
try {
51-
$csv = Writer::createFromString();
51+
$csv = Writer::fromString();
5252
$csv->setDelimiter($delimiter);
5353
$csv->insertAll($data);
5454

src/Grid/Column/Resolver/DataObject/AdapterResolver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public function resolveForExport(Column $column, ElementInterface $element, User
6868

6969
$classDefinition = $element->getClass();
7070
$fieldDefinition = $this->getFieldDefinition($column->getKey(), $classDefinition);
71-
$value = $this->dataService->getExportFieldValue($element, $fieldDefinition, $column->getKey());
71+
72+
$context = new FieldContextData(
73+
legacyParameters: ['language' => $column->getLocale()]
74+
);
75+
76+
$value = $this->dataService->getExportFieldValue($element, $fieldDefinition, $column->getKey(), $context);
7277

7378
return $this->getColumnData($column, $value, $fieldDefinition->getFieldType());
7479
}

src/Grid/Service/GridService.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function getConfigurationForExport(
281281
public function getColumnKeys(ColumnCollection $columnCollection, bool $withGroup = false): array
282282
{
283283
return array_map(
284-
static function (Column $column) use ($withGroup) {
284+
function (Column $column) use ($withGroup) {
285285
if ($withGroup === true && !$column->getGroup()) {
286286
throw new InvalidArgumentException('Group must be set when withGroup is true');
287287
}
@@ -294,12 +294,24 @@ static function (Column $column) use ($withGroup) {
294294
$key = $fd ? ($fd['title'] ?? $column->getKey()) : $column->getKey();
295295
}
296296

297+
$key = $this->appendLocale($key, $column);
298+
297299
return ($withGroup ? $firstGroup . '~' : '') . $key;
298300
},
299301
$columnCollection->getColumns()
300302
);
301303
}
302304

305+
private function appendLocale(string $key, Column $column): string
306+
{
307+
$locale = $column->getLocale();
308+
if ($locale !== null) {
309+
return $key . ' (' . $locale . ')';
310+
}
311+
312+
return $key;
313+
}
314+
303315
/**
304316
* @throws InvalidArgumentException
305317
*/

0 commit comments

Comments
 (0)