Skip to content
Snippets Groups Projects
Commit 0d5bd1a9 authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #3384225: Empty charts added on every save, can't remove charts

parent f132b03d
No related branches found
No related tags found
1 merge request!66Update ChartConfigItemDefaultFormatter.php
Pipeline #39463 passed with warnings
......@@ -55,9 +55,32 @@ class ChartConfigItemDefaultFormatter extends FormatterBase {
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
*/
protected function viewElement(FieldItemInterface $item, $chart_id) {
protected function viewElement(FieldItemInterface $item, string $chart_id) {
$settings = $item->toArray()['config'];
return Chart::buildElement($settings, $chart_id);
if ($this->hasData($settings['series']['data_collector_table'])) {
return Chart::buildElement($settings, $chart_id);
}
return [];
}
/**
* Checks if the chart has data.
*
* @param array $data_collector_table
* The data collector table.
*
* @return bool
* TRUE if the chart has data, FALSE otherwise.
*/
protected function hasData(array $data_collector_table) {
foreach ($data_collector_table as $row) {
foreach ($row as $cell) {
if (!empty($cell['data'])) {
return TRUE;
}
}
}
return FALSE;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment