public function GoogleMapFieldEmbedPlaceFormatter::viewElements in Google Map Field 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
File
- src/
Plugin/ Field/ FieldFormatter/ GoogleMapFieldEmbedPlaceFormatter.php, line 77
Class
- GoogleMapFieldEmbedPlaceFormatter
- Plugin implementation of the 'google_map_field' formatter.
Namespace
Drupal\google_map_field\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$api_key = $this->configFactory
->get('google_map_field.settings')
->get('google_map_field_apikey');
$elements = [];
foreach ($items as $delta => $item) {
$element = [
'#theme' => 'google_map_field_embed',
'#name' => $item->name,
'#lat' => $item->lat,
'#lon' => $item->lon,
'#zoom' => $item->zoom,
'#type' => $item->type,
'#show_marker' => $item->marker === "1" ? "true" : "false",
'#show_controls' => $item->controls === "1" ? "true" : "false",
'#width' => $item->width ? $item->width : '320px',
'#height' => $item->height ? $item->height : '200px',
'#api_key' => $api_key,
];
// Handle markup for InfoWindow popup.
if (!empty($item->infowindow)) {
$element['#infowindow'] = [
'#markup' => $item->infowindow,
'#allowed_tags' => $this
->allowedTags(),
];
}
$elements[$delta] = $element;
}
return $elements;
}