GeolocationGoogleWidget.php in Geolocation Field 8.3
File
modules/geolocation_google_maps/src/Plugin/Field/FieldWidget/GeolocationGoogleWidget.php
View source
<?php
namespace Drupal\geolocation_google_maps\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\geolocation\Plugin\Field\FieldWidget\GeolocationMapWidgetBase;
use Drupal\Core\Render\BubbleableMetadata;
class GeolocationGoogleWidget extends GeolocationMapWidgetBase {
protected static $mapProviderId = 'google_maps';
protected static $mapProviderSettingsFormId = 'google_map_settings';
public static function defaultSettings() {
$settings = parent::defaultSettings();
$settings[self::$mapProviderSettingsFormId]['map_features']['control_geocoder'] = [
'enabled' => TRUE,
'weight' => -100,
];
$settings[self::$mapProviderSettingsFormId]['map_features']['control_recenter']['enabled'] = TRUE;
$settings[self::$mapProviderSettingsFormId]['map_features']['control_locate']['enabled'] = TRUE;
return $settings;
}
public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta = NULL) {
$element = parent::form($items, $form, $form_state, $get_delta);
$element['#attributes']['data-widget-type'] = 'google';
$element['#attached'] = BubbleableMetadata::mergeAttachments($element['#attached'], [
'library' => [
'geolocation_google_maps/widget.google',
],
]);
return $element;
}
}