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

Issue #3481760 by andileco, nikathone: Add entity to the Chart element when a...

Issue #3481760 by andileco, nikathone: Add entity to the Chart element when a Chart field is used to enable retrieval of entity values in charts hooks
parent 2efe9bac
No related branches found
No related tags found
No related merge requests found
Pipeline #356745 failed
......@@ -120,6 +120,11 @@ function hook_chart_definition_alter(array &$definition, array $element, $chart_
}
elseif ($element['#chart_library'] === 'highcharts') {
$definition['title']['style']['fontSize'] = 20;
// 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;
}
}
}
......
......@@ -30,6 +30,7 @@ class ChartConfigItemDefaultFormatter extends FormatterBase {
$entity_uuid = $entity->uuid();
$entity_type_id = $entity->getEntityTypeId();
$bundle = $entity->bundle();
$field_name = $items->getName();
$chart_id = $entity_type_id . '__' . $bundle;
foreach ($items as $delta => $item) {
......@@ -37,6 +38,8 @@ class ChartConfigItemDefaultFormatter extends FormatterBase {
$elements[$delta] = $this->viewElement($item, $chart_id);
$elements[$delta]['#id'] = Html::getUniqueId($id);
$elements[$delta]['#chart_id'] = $chart_id;
$elements[$delta]['#entity'] = $entity;
$elements[$delta]['#field_name'] = $field_name;
}
return $elements;
......
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