You are here

public function GeocodeFormatterBase::viewElements in Geocoder 8.2

Same name and namespace in other branches
  1. 8.3 modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php \Drupal\geocoder_field\Plugin\Field\GeocodeFormatterBase::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

3 methods override GeocodeFormatterBase::viewElements()
AddressGeocodeFormatter::viewElements in modules/geocoder_address/src/Plugin/Field/FieldFormatter/AddressGeocodeFormatter.php
Builds a renderable array for a field value.
FileGeocodeFormatter::viewElements in modules/geocoder_field/src/Plugin/Field/FieldFormatter/FileGeocodeFormatter.php
Builds a renderable array for a field value.
ReverseGeocodeGeofieldFormatter::viewElements in modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/ReverseGeocodeGeofieldFormatter.php
Builds a renderable array for a field value.

File

modules/geocoder_field/src/Plugin/Field/GeocodeFormatterBase.php, line 216

Class

GeocodeFormatterBase
Base Plugin implementation of the Geocode formatter.

Namespace

Drupal\geocoder_field\Plugin\Field

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $dumper = $this->dumperPluginManager
    ->createInstance($this
    ->getSetting('dumper'));
  $provider_plugins = $this
    ->getEnabledProviderPlugins();
  foreach ($items as $delta => $item) {
    if ($address_collection = $this->geocoder
      ->geocode($item->value, array_keys($provider_plugins))) {
      $elements[$delta] = [
        '#plain_text' => $dumper
          ->dump($address_collection
          ->first()),
      ];
    }
  }
  return $elements;
}