You are here

public function ChartConfigItemDefaultFormatter::viewElements in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x src/Plugin/Field/FieldFormatter/ChartConfigItemDefaultFormatter.php \Drupal\charts\Plugin\Field\FieldFormatter\ChartConfigItemDefaultFormatter::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/ChartConfigItemDefaultFormatter.php, line 27

Class

ChartConfigItemDefaultFormatter
Plugin implementation of the "chart_config_default" formatter.

Namespace

Drupal\charts\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $entity = $items
    ->getEntity();
  $entity_uuid = $entity
    ->uuid();
  $entity_type_id = $entity
    ->getEntityTypeId();
  $bundle = $entity
    ->bundle();
  $chart_id = $entity_type_id . '__' . $bundle;
  foreach ($items as $delta => $item) {
    $id = 'charts-item--' . $entity_uuid . '--' . $delta;
    $elements[$delta] = $this
      ->viewElement($item, $chart_id);
    $elements[$delta]['#id'] = Html::getUniqueId($id);
    $elements[$delta]['#chart_id'] = $chart_id;
  }
  return $elements;
}