Closed (fixed)
Project:
Charts
Version:
5.0.x-dev
Component:
Chart API
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
18 Oct 2024 at 14:44 UTC
Updated:
16 Dec 2024 at 19:49 UTC
Jump to comment: Most recent
For users who are using the Chart Field and want to incorporate information from the entity into the chart (rather than needing to alter the Chart form), we should pass the entity and the field name to the Chart element.
The API doesn't change, but now you can access the entity (i.e. node) like this:
function MYMODULE_chart_definition_alter(array &$definition, array $element, $chart_id) {
if ($element['#chart_library'] === 'highcharts') {
// Add a caption based on a field on your node containing a Chart field.
$node = $element['#entity'];
if ($node instanceof \Drupal\node\NodeInterface && $node->hasField('field_caption')) {
$definition['caption']['text'] = $node->field_caption->value ?? '';
}
}
}
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 #4
andileco commentedComment #6
andileco commentedThis was reviewed on Slack: https://drupal.slack.com/archives/C878FC7HS/p1729289428068719?thread_ts=...
Comment #8
andileco commentedComment #10
andileco commented