GeolocationZoomGoogleMapFormatter.php in Geolocation Address Link 8
File
src/Plugin/Field/FieldFormatter/GeolocationZoomGoogleMapFormatter.php
View source
<?php
namespace Drupal\geolocation_address_link\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationGoogleMapFormatter;
class GeolocationZoomGoogleMapFormatter extends GeolocationGoogleMapFormatter {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
if (empty($elements)) {
return $elements;
}
if (array_key_exists('#attached', $elements)) {
$data = $items
->get(0)
->getValue()['data'];
if (array_key_exists('zoom', $data)) {
$unique_id = $elements['#uniqueid'];
$elements['#attached']['drupalSettings']['geolocation']['maps'][$unique_id]['settings']['google_map_settings']['zoom'] = $data['zoom'];
}
}
else {
foreach ($elements as $delta => $element) {
$data = $items
->get($delta)
->getValue()['data'];
if (array_key_exists('zoom', $data)) {
$unique_id = $element['#uniqueid'];
$elements[$delta]['#attached']['drupalSettings']['geolocation']['maps'][$unique_id]['settings']['google_map_settings']['zoom'] = $data['zoom'];
}
}
}
return $elements;
}
}