public function FileGeocodeFormatter::viewElements in Geocoder 8.3
Same name and namespace in other branches
- 8.2 modules/geocoder_field/src/Plugin/Field/FieldFormatter/FileGeocodeFormatter.php \Drupal\geocoder_field\Plugin\Field\FieldFormatter\FileGeocodeFormatter::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 GeocodeFormatterBase::viewElements
1 method overrides FileGeocodeFormatter::viewElements()
- GeoPhpGeocodeFormatter::viewElements in modules/
geocoder_geofield/ src/ Plugin/ Field/ FieldFormatter/ GeoPhpGeocodeFormatter.php - Builds a renderable array for a field value.
File
- modules/
geocoder_field/ src/ Plugin/ Field/ FieldFormatter/ FileGeocodeFormatter.php, line 193
Class
- FileGeocodeFormatter
- Plugin implementation of the Geocode formatter for File and Image fields.
Namespace
Drupal\geocoder_field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
try {
/* @var \Drupal\geocoder\DumperInterface $dumper */
$dumper = $this->dumperPluginManager
->createInstance($this
->getSetting('dumper'));
/* @var \Drupal\geocoder_field\PreprocessorInterface $preprocessor */
$preprocessor = $this->preprocessorManager
->createInstance('file');
$preprocessor
->setField($items)
->preprocess();
$providers = $this
->getEnabledGeocoderProviders();
foreach ($items as $delta => $item) {
if ($address_collection = $this->geocoder
->geocode($item->value, $providers)) {
$elements[$delta] = [
'#markup' => $dumper
->dump($address_collection
->first()),
];
}
}
} catch (\Exception $e) {
watchdog_exception('geocoder', $e);
}
return $elements;
}