silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
721 stars 821 forks source link

Export fields that are not a key value pair are blank (if the list is different to summary_fields) #9417

Open mlewis-everley opened 4 years ago

mlewis-everley commented 4 years ago

Affected Version

SilverStripe 4.3+

Description

If I create a DataObject and give it different summary_fields and export_fields, but use a simple sequential array for export_fields, then the export field values are blank.

Steps to Reproduce

Create a DataObject like the following:

class Product extends DataObject implements PermissionProvider
{
    private static $db = [
        "Title"             => "Varchar(255)",
        "StockID"           => "Varchar",
        "BasePrice"         => "Currency",
        "Content"           => "HTMLText",
        "ContentSummary"    => "Text",
        "Weight"            => "Decimal",
        "Disabled"          => "Boolean"
    ];

    private static $casting = [
        "MenuTitle"             => "Varchar",
        "CategoriesList"        => "Varchar",
        "TagsList"              => "Varchar",
        "ImagesList"            => "Varchar",
        "RelatedProductsList"   => "Varchar",
        "CMSThumbnail"          => "Varchar",
        "Price"                 => "Currency",
        "TaxID"                 => "Int",
        "TaxRate"               => "Decimal",
        "TaxAmount"             => "Currency",
        "PriceAndTax"           => "Currency",
        "TaxString"             => "Varchar",
        "IncludesTax"           => "Boolean"
    ];

    private static $summary_fields = [
        "CMSThumbnail"          => "Thumbnail",
        "ClassName"             => "Product",
        "StockID"               => "StockID",
        "Title"                 => "Title",
        "BasePrice"             => "Price",
        "TaxRate"               => "Tax Percent",
        "CategoriesList"        => "Categories",
        "TagsList"              => "Tags",
        "Disabled"              => "Disabled"
    ];

    private static $export_fields = [
        "ID",
        "StockID",
        "ClassName",
        "Title",
        "Content",
        "BasePrice",
        "TaxRate",
        "CategoriesList",
        "TagsList",
        "ImagesList",
        "RelatedProductsList",
        "Disabled"
    ];
}

Now add a simple ModelAdmin to manage these items, add some and try to export. All fields (other than ImagesList) are null.

This issue appears to be related to #9244 , but the fix mentioned doesn't fix this issue. I am not sure if this is expected functionality, but in my mind, export_fields should work like summary_fields and fall back to using $record->fieldLabel().

emteknetnz commented 4 years ago

Thank you for reporting this. In terms of getting this resolved in a timely manner, just letting you know that the team at Silverstripe Ltd set bugfix priorities based on the impact of the bug with critical being the highest, so at this stage we cannot say when we’ll get a chance to look at this further.

If other people are experiencing this same issue then we'd encourage them to share their experiences here, which can help raise the priority on getting this issue resolved. Please follow the guide about what is useful when making bug reports.

Community help creating a pull-request for this is most welcome, so perhaps this is something that you could do? Read more about contributing code.

rafaeldsousa commented 4 years ago

Yep, just found myself in the same situation. Exact same scenario, export fields had non key value fields and were different from summary fields. That resulted in the non key value fields being blank in the export file. If updating summary fields to the same as the export, the values would be displayed. Updating export fields to all have key => value, export file also had values as expected.