1 | <?php |
||
10 | class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionProvider, GridField_URLHandler { |
||
11 | |||
12 | /** |
||
13 | * @var array Map of a property name on the exported objects, with values being the column title in the CSV file. |
||
14 | * Note that titles are only used when {@link $csvHasHeader} is set to TRUE. |
||
15 | */ |
||
16 | protected $exportColumns; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $csvSeparator = ","; |
||
22 | |||
23 | /** |
||
24 | * @var boolean |
||
25 | */ |
||
26 | protected $csvHasHeader = true; |
||
27 | |||
28 | /** |
||
29 | * Fragment to write the button to |
||
30 | */ |
||
31 | protected $targetFragment; |
||
32 | |||
33 | /** |
||
34 | * Set to true to disable XLS sanitisation |
||
35 | * [SS-2017-007] Ensure all cells with leading [@=+] have a leading tab |
||
36 | * |
||
37 | * @config |
||
38 | * @var bool |
||
39 | */ |
||
40 | private static $xls_export_disabled = false; |
||
41 | |||
42 | /** |
||
43 | * @param string $targetFragment The HTML fragment to write the button into |
||
44 | * @param array $exportColumns The columns to include in the export |
||
45 | */ |
||
46 | public function __construct($targetFragment = "after", $exportColumns = null) { |
||
50 | |||
51 | /** |
||
52 | * Place the export button in a <p> tag below the field |
||
53 | */ |
||
54 | public function getHTMLFragments($gridField) { |
||
69 | |||
70 | /** |
||
71 | * export is an action button |
||
72 | */ |
||
73 | public function getActions($gridField) { |
||
76 | |||
77 | public function handleAction(GridField $gridField, $actionName, $arguments, $data) { |
||
82 | |||
83 | /** |
||
84 | * it is also a URL |
||
85 | */ |
||
86 | public function getURLHandlers($gridField) { |
||
91 | |||
92 | /** |
||
93 | * Handle the export, for both the action button and the URL |
||
94 | */ |
||
95 | public function handleExport($gridField, $request = null) { |
||
103 | |||
104 | /** |
||
105 | * Return the columns to export |
||
106 | * |
||
107 | * @param GridField $gridField |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | protected function getExportColumnsForGridField(GridField $gridField) { |
||
122 | |||
123 | /** |
||
124 | * Generate export fields for CSV. |
||
125 | * |
||
126 | * @param GridField $gridField |
||
127 | * @return string |
||
128 | */ |
||
129 | public function generateExportFileData($gridField) { |
||
211 | |||
212 | /** |
||
213 | * @return array |
||
214 | */ |
||
215 | public function getExportColumns() { |
||
218 | |||
219 | /** |
||
220 | * @param array |
||
221 | */ |
||
222 | public function setExportColumns($cols) { |
||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getCsvSeparator() { |
||
233 | |||
234 | /** |
||
235 | * @param string |
||
236 | */ |
||
237 | public function setCsvSeparator($separator) { |
||
241 | |||
242 | /** |
||
243 | * @return boolean |
||
244 | */ |
||
245 | public function getCsvHasHeader() { |
||
248 | |||
249 | /** |
||
250 | * @param boolean |
||
251 | */ |
||
252 | public function setCsvHasHeader($bool) { |
||
256 | |||
257 | |||
258 | } |
||
259 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needle
but will only accept an array as$haystack
.