/** * Helper function to print the actual chart. * * @param $item \Drupal\Core\Field\FieldItemInterface * The field item * @param int $entity_id * The entity id * @param int $delta * The delta * * @return string $output * The field output. */ public function easychartPrintChart(FieldItemInterface $item, $entity_id, $delta) { $values = $item->getValue(); $output = []; // Verify csv being given. if (empty($values['csv'])) { return FALSE; } else { // Print a div for js to pick up & render chart. $output['markup'] = '<div class="easychart-embed--' . $entity_id . '-' . $delta . '"></div>'; // Add config to output. $output['config'] = $values['config']; // Add csv to output. $output['csv'] = !empty($values['csv']) ? $values['csv'] : ''; } return $output; }
/** * {@inheritdoc} */ public function viewFieldItem(FieldItemInterface $item, $display = array()) { $entity = $item->getEntity(); $field_name = $item->getFieldDefinition()->getName(); // Clone the entity since we are going to modify field values. $clone = clone $entity; // Push the item as the single value for the field, and defer to viewField() // to build the render array for the whole list. $clone->{$field_name}->setValue(array($item->getValue())); $elements = $this->viewField($clone->{$field_name}, $display); // Extract the part of the render array we need. $output = isset($elements[0]) ? $elements[0] : array(); if (isset($elements['#access'])) { $output['#access'] = $elements['#access']; } return $output; }