From 3d989a6eae979f2671889376179dfdc7085658ac Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Fri, 9 Aug 2019 14:51:56 +1200 Subject: [PATCH] FIX Use content generated by DataColumns component for print and csv export --- src/Forms/GridField/GridFieldExportButton.php | 7 +++++++ src/Forms/GridField/GridFieldPrintButton.php | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Forms/GridField/GridFieldExportButton.php b/src/Forms/GridField/GridFieldExportButton.php index 4c4d41eac..eb8698b72 100644 --- a/src/Forms/GridField/GridFieldExportButton.php +++ b/src/Forms/GridField/GridFieldExportButton.php @@ -214,6 +214,9 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP } } + /** @var GridFieldDataColumns|null $gridFieldColumnsComponent */ + $gridFieldColumnsComponent = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); + /** @var DataObject $item */ foreach ($items->limit(null) as $item) { if (!$item->hasMethod('canView') || $item->canView()) { @@ -228,6 +231,10 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP } $value = $columnHeader($relObj); + } elseif ($gridFieldColumnsComponent) { + $value = strip_tags( + $gridFieldColumnsComponent->getColumnContent($gridField, $item, $columnSource) + ); } else { $value = $gridField->getDataFieldValue($item, $columnSource); diff --git a/src/Forms/GridField/GridFieldPrintButton.php b/src/Forms/GridField/GridFieldPrintButton.php index aba827282..547997899 100644 --- a/src/Forms/GridField/GridFieldPrintButton.php +++ b/src/Forms/GridField/GridFieldPrintButton.php @@ -156,7 +156,7 @@ class GridFieldPrintButton implements GridField_HTMLProvider, GridField_ActionPr } /** @var GridFieldDataColumns $dataCols */ - $dataCols = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); + $dataCols = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); if ($dataCols) { return $dataCols->getDisplayFields($gridField); } @@ -223,12 +223,17 @@ class GridFieldPrintButton implements GridField_HTMLProvider, GridField_ActionPr $items = $gridField->getManipulatedList(); $itemRows = new ArrayList(); + /** @var GridFieldDataColumns $gridFieldColumnsComponent */ + $gridFieldColumnsComponent = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); + /** @var DataObject $item */ foreach ($items->limit(null) as $item) { $itemRow = new ArrayList(); foreach ($printColumns as $field => $label) { - $value = $gridField->getDataFieldValue($item, $field); + $value = $gridFieldColumnsComponent + ? strip_tags($gridFieldColumnsComponent->getColumnContent($gridField, $item, $field)) + : $gridField->getDataFieldValue($item, $field); $itemRow->push(new ArrayData(array( "CellString" => $value,