You are here

public function GeofieldDefaultFormatter::viewElements in Geofield 8

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

1 method overrides GeofieldDefaultFormatter::viewElements()
LatLonFormatter::viewElements in src/Plugin/Field/FieldFormatter/LatLonFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php, line 149

Class

GeofieldDefaultFormatter
Plugin implementation of the 'geofield_default' formatter.

Namespace

Drupal\geofield\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  foreach ($items as $delta => $item) {
    $geom = $this->geoPhpWrapper
      ->load($item->value);
    $output = $geom ? $geom
      ->out($this
      ->getOutputFormat()) : '';
    if ($this
      ->getSetting('output_escape')) {
      $output = Html::escape($output);
    }
    $elements[$delta] = [
      '#markup' => $output,
    ];
  }
  return $elements;
}