Problem/Motivation
When uploading a CSV file to a Chart paragraph via the "Import Data from CSV" feature, an AJAX parsererror (HTTP 200) occurs and the data is not imported. The root cause is a PHP deprecation notice emitted by fgetcsv() in ChartDataCollectorTable.php, which is rendered into the response body before the JSON payload, causing the AJAX handler to fail to parse the response.
On a second upload attempt (with an empty data table), the corrupted form state can cause an unrelated component to be inserted erroneously.
The deprecation notice reads:
Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in .../charts/src/Element/ChartDataCollectorTable.php on line 476
This affects environments where PHP deprecation notices are rendered (e.g. development environments or servers with display_errors on), and will become a hard error in a future PHP version.
Steps to reproduce
1. Create a node with a Chart paragraph
2. In the Chart field, open the "Import Data from CSV" section
3. Upload a valid CSV file and click "Upload CSV"
4. Observe the browser console — an AJAX HTTP error with StatusText: parsererror is logged
5. The chart data table fields remain empty
Expected behaviour:
The CSV data is parsed and populated into the chart data table fields without error.
Actual behaviour:
The AJAX response fails with a parsererror due to the PHP deprecation notice being prepended to the JSON response body. On a second upload attempt the form state is corrupt and an unrelated component may be inserted.
Proposed resolution
In src/Element/ChartDataCollectorTable.php line 476, explicitly provide the $enclosure and $escape arguments to fgetcsv():
- while ($row = fgetcsv($handle, 0, $separator)) {
+ while ($row = fgetcsv($handle, 0, $separator, '"', '\\')) {This matches the historical defaults and silences the deprecation notice in PHP 8.1+, restoring correct AJAX behaviour.
| Comment | File | Size | Author |
|---|---|---|---|
| fgetcsv-escape-param.patch | 745 bytes | james hawthorn-byng |
Issue fork charts-3595482
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nikathoneThis is a good suggestion @james-hawthorn-byng. Could you please provide it as a MR? If in the future people need to be able to provide different values for the enclosure and $escape arguments to fgetcsv() we can make it configurable.
Comment #3
pfaocleJust to note this addresses the issue for me. Thanks!
Comment #6
andileco commentedI'm on a Charts issue spree, so went ahead and created the MR based on @james hawthorn-byn's post.
Comment #7
nikathoneComment #9
andileco commented