public function GeocodeFormatterBase::viewElements in Geocoder 8.3
Same name and namespace in other branches
- 8.2 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 246
Class
- GeocodeFormatterBase
- Base Plugin implementation of the Geocode formatter.
Namespace
Drupal\geocoder_field\Plugin\FieldCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
try {
$dumper = $this->dumperPluginManager
->createInstance($this
->getSetting('dumper'));
} catch (PluginException $e) {
$this->loggerFactory
->get('geocoder')
->error('No Dumper has been set');
}
$providers = $this
->getEnabledGeocoderProviders();
foreach ($items as $delta => $item) {
if ($address_collection = $this->geocoder
->geocode($item->value, $providers)) {
$elements[$delta] = [
'#markup' => $address_collection instanceof AddressCollection && !$address_collection
->isEmpty() ? $dumper
->dump($address_collection
->first()) : "",
];
}
}
return $elements;
}