Skip to content

Commit

Permalink
FIX: Modifications to GridFieldExportButton to allow ArrayList use in…
Browse files Browse the repository at this point in the history
… SS_Report
  • Loading branch information
wilr committed May 6, 2015
1 parent 5f5662b commit 828ad6e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions forms/gridfield/GridFieldExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function generateExportFileData($gridField) {
}

foreach($items->limit(null) as $item) {
if($item->hasMethod('canView') && $item->canView()) {
if(!$item->hasMethod('canView') || $item->canView()) {
$columnData = array();

foreach($csvColumns as $columnSource => $columnHeader) {
Expand All @@ -146,16 +146,23 @@ public function generateExportFileData($gridField) {
$value = $columnHeader($relObj);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);

if(!$value) {

This comment has been minimized.

Copy link
@nglasl

nglasl Jun 2, 2015

Having updated to 3.1.13, I noticed that this change has resulted in an export to CSV bug when using custom export fields. Basically, if $value ends up being null, it will attempt to use the column heading that you've defined. If your column heading happens to contain the dot notation (for relationships), it will fail to resolve and throw an error. An example of this would be the following, where the dot notation has been used to clarify where the field is coming from..

$export = array(
    'Field' => 'Class.Field'
);

If Field ends up being null (which is completely valid), it will try to resolve Class.Field incorrectly. This results in..

[User Error] Class is not a relation/field on Class

This comment has been minimized.

Copy link
@oddnoc
$value = $gridField->getDataFieldValue($item, $columnHeader);
}
}

$value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '""', $value) . '"';
}

$fileData .= implode($separator, $columnData);
$fileData .= "\n";
}

$item->destroy();
if($item->hasMethod('destroy')) {
$item->destroy();
}
}

return $fileData;
Expand Down

0 comments on commit 828ad6e

Please sign in to comment.