You are here

public function GeofieldMapWidget::formElement in Geofield Map 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/GeofieldMapWidget.php \Drupal\geofield_map\Plugin\Field\FieldWidget\GeofieldMapWidget::formElement()

Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().

Overrides GeofieldLatLonWidget::formElement

File

src/Plugin/Field/FieldWidget/GeofieldMapWidget.php, line 643

Class

GeofieldMapWidget
Plugin implementation of the 'geofield_map' widget.

Namespace

Drupal\geofield_map\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  $gmap_api_key = $this
    ->getGmapApiKey();
  $latlon_value = [];
  foreach ($this->components as $component) {
    $latlon_value[$component] = isset($items[$delta]->{$component}) ? floatval($items[$delta]->{$component}) : $this
      ->getSetting('default_value')[$component];
  }
  $element += [
    '#gmap_api_key' => $gmap_api_key,
    '#gmap_places' => $this
      ->getSetting('map_google_places')['places_control'],
    '#gmap_places_options' => $this
      ->getSetting('map_google_places')['places_additional_options'],
    '#type' => 'geofield_map',
    '#default_value' => $latlon_value,
    '#geolocation' => $this
      ->getSetting('html5_geolocation'),
    '#geofield_map_geolocation_override' => $this
      ->getSetting('html5_geolocation'),
    '#map_library' => $this
      ->getSetting('map_library'),
    '#map_type' => 'leaflet' === $this
      ->getSetting('map_library') ? $this
      ->getSetting('map_type_leaflet') : $this
      ->getSetting('map_type_google'),
    '#map_type_selector' => $this
      ->getSetting('map_type_selector'),
    '#map_types_google' => $this->gMapTypesOptions,
    '#map_types_leaflet' => $this->leafletTileLayers,
    '#map_dimensions' => $this
      ->getSetting('map_dimensions'),
    '#zoom' => $this
      ->getSetting('zoom'),
    '#click_to_find_marker' => $this
      ->getSetting('click_to_find_marker'),
    '#click_to_place_marker' => $this
      ->getSetting('click_to_place_marker'),
    '#geoaddress_field' => $this
      ->getSetting('geoaddress_field'),
    '#error_label' => !empty($element['#title']) ? $element['#title'] : $this->fieldDefinition
      ->getLabel(),
  ];
  return [
    'value' => $element,
  ];
}