|
| 1 | +--- |
| 2 | +title: Site-Wide Content Report |
| 3 | +summary: Customizing the columns of the site-wide Content Report and improvoing performance of large datasets |
| 4 | +icon: file-alt |
| 5 | +--- |
| 6 | + |
| 7 | +# Site-wide content report |
| 8 | + |
| 9 | +## Customising the report |
| 10 | + |
| 11 | +In order to customise the columns included in a report you can build a custom extension and apply it to the |
| 12 | +SitewideContentReport as necessary. |
| 13 | + |
| 14 | +The built in [`SitewideContentTaxonomy`](api:SilverStripe\Reports\SiteWideContentReport\Extensions\SitewideContentTaxonomy) extension, for instance, adds a custom columns extracted from the [`Taxonomies`](https://docs.silverstripe.org/en/optional_features/taxonomies/) module, and can be used as a base for developing further extensions: |
| 15 | + |
| 16 | +For instance, in order to add a new Page field to the report you could add an extension similar to the below: |
| 17 | + |
| 18 | +```php |
| 19 | +namespace App\Extensions; |
| 20 | + |
| 21 | +use SilverStripe\Core\Extension; |
| 22 | +use SilverStripe\Reports\SiteWideContentReport\Reports\SiteWideContentReport; |
| 23 | + |
| 24 | +class MyReportExtension extends Extension |
| 25 | +{ |
| 26 | + protected function updateColumns($itemType, &$columns) |
| 27 | + { |
| 28 | + if($itemType !== 'Pages') { |
| 29 | + return; |
| 30 | + } |
| 31 | + $columns["Price"] = [ |
| 32 | + "title" => _t(SitewideContentReport::class . ".Price", "Price"), |
| 33 | + "formatting" => function ($value, $item) use ($mainSiteLabel) { |
| 34 | + return number_format($value, 2, '.', ','); |
| 35 | + }, |
| 36 | + ]; |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +The `$columns` array can have any number of items added, where the key of the array represents the |
| 42 | +field name to be included. |
| 43 | + |
| 44 | +Each item can be either a literal string (which will be used as the title), or an array that may contain |
| 45 | +the following key => value pairs: |
| 46 | + |
| 47 | + * `title`: The title to use for the column header |
| 48 | + * `format`: A method callback which will take the raw value and original object, and return a formatted |
| 49 | + string. |
| 50 | + * `datasource`: If the value for this column isn't a direct field on the original object, a custom callback |
| 51 | + can be set here. Unlike `format` this callback will only take a single parameter, the original object. |
| 52 | + * `printonly`: Set to true if this column is only visible on the print or export-to-csv views. |
| 53 | + * `casting`: Specify a field type (e.g. `Text` or `Int`) in order to assist with field casting. This is not |
| 54 | + necessary if `formatting` is used. |
| 55 | + |
| 56 | +## Performance considerations |
| 57 | + |
| 58 | +### Large data sets |
| 59 | + |
| 60 | +If your project has a large number of pages or files, you may experience server timeouts while trying to export |
| 61 | +this report to CSV. To avoid this issue, you can either increase your server timeout limit, or you can install |
| 62 | +and configure the [silverstripe/gridfieldqueuedexport module](https://github.com/silverstripe/silverstripe-gridfieldqueuedexport) |
| 63 | +which allows for CSV generation to offloaded to a queued job in the background. |
| 64 | + |
| 65 | +An example of configuring this module in your project: |
| 66 | + |
| 67 | +```php |
| 68 | +namespace App\Extensions; |
| 69 | + |
| 70 | +use SilverStripe\Core\Extension; |
| 71 | +use SilverStripe\Forms\GridField\GridFieldComponent; |
| 72 | +use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton; |
| 73 | + |
| 74 | +class SitewideContentReportQueuedExportExtension extends Extension |
| 75 | +{ |
| 76 | + protected function updateExportButton(GridFieldComponent &$exportButton) |
| 77 | + { |
| 78 | + $exportButton = GridFieldQueuedExportButton::create('buttons-after-left'); |
| 79 | + } |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +Apply the example Extension above with YAML configuration in your project: |
| 84 | + |
| 85 | +```yml |
| 86 | +--- |
| 87 | +Name: queuedsitewidecontentreport |
| 88 | +--- |
| 89 | +SilverStripe\Reports\SitewideContentReport\Reports\SitewideContentReport: |
| 90 | + extensions: |
| 91 | + - 'App\Extensions\SitewideContentReportQueuedExportExtension' |
| 92 | +``` |
| 93 | +
|
0 commit comments