Problem/Motivation
How it works in 5.0.x
In the field of type chart_config, I can set a default value by only specifying the “Charting library” and “Chart type” properties without entering any data in the series inputs. This feature is particularly useful when you want to pre-define specific chart settings for editors in the field widget. All they need to do is enter actual data when creating a chart.
But this was broken in 5.1.x
If you only specify things like “Charting library” or “Chart type” in the field’s default value configuration, but leave “series” empty, you won’t get these settings predefined in the field widget. This is because your “default value” is marked as “empty” and is ignored.
Root cause
https://git.drupalcode.org/project/charts/-/commit/2d293e853bcf10af73dc9...
Specifically changes in the src/Plugin/Field/FieldType/ChartConfigItem.php isEmpty method.
Steps to reproduce
1. Enable the Charts module and a few submodules, such as chartsjs and highchats.
2. Add a new “Chart” field to the Article content type.
3. When creating the field, check the “Set default value” checkbox and then set “Charting library” to Chart.js. Do not set any other values. Save the field.
4. Go to /node/add/article and observe that the “Chart” field does not have “Charting library” preselected with Chart.js, even though the default value was set for the field.
Proposed resolution
Requiring actual chart data to be entered in the default field value while making sense to ensure no empty chart is ever displayed removes the ability to set up a default chart config for Editors. We need to keep the ability to set up a default chart config for the field instance.
Issue fork charts-3590044
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
andileco commentedThanks for reporting this issue! Are you planning to create the patch?
Comment #3
santanu mondal commented@edwardsay Hi I have enable the set default checkbox and it was ask me to set the charts configuration then when you fill the details then the charts will showing .
If if you are telling about this issue then please check once and if not then add the proper step to produce.
Comment #4
edwardsay commentedComment #6
edwardsay commentedI've opened MR that fixes this issue by reverting the isEmpty() logic in ChartConfigItem.php back to what it was in v5.0. This allows chart configurations to be saved without requiring series data.
But I kept Formatter changes, so empty charts are still prevented from rendering via the hasData() check in ChartConfigItemDefaultFormatter.php
Comment #7
edwardsay commented