GeolocationLeafletWidget.php in Geolocation Field 8.2
File
modules/geolocation_leaflet/src/Plugin/Field/FieldWidget/GeolocationLeafletWidget.php
View source
<?php
namespace Drupal\geolocation_leaflet\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 GeolocationLeafletWidget extends GeolocationMapWidgetBase {
protected static $mapProviderId = 'leaflet';
protected static $mapProviderSettingsFormId = 'leaflet_settings';
public static function defaultSettings() {
$settings = parent::defaultSettings();
$settings[self::$mapProviderSettingsFormId]['map_features']['leaflet_control_geocoder'] = [
'enabled' => TRUE,
'weight' => -100,
];
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['#attached'] = BubbleableMetadata::mergeAttachments($element['#attached'], [
'library' => [
'geolocation_leaflet/widget.leaflet',
],
]);
return $element;
}
}