You are here

public function GoogleMapsDisplayTrait::getGoogleMapsSettingsForm in Geolocation Field 8

Provide a generic map settings form array.

Parameters

array $settings: The current map settings.

string $form_prefix: Form specific optional prefix.

Return value

array A form array to be integrated in whatever.

4 calls to GoogleMapsDisplayTrait::getGoogleMapsSettingsForm()
CommonMap::buildOptionsForm in src/Plugin/views/style/CommonMap.php
Provide a form to edit options for this plugin.
GeolocationGooglegeocoderWidget::formElement in src/Plugin/Field/FieldWidget/GeolocationGooglegeocoderWidget.php
Returns the form for a single field widget.
GeolocationGooglegeocoderWidget::settingsForm in src/Plugin/Field/FieldWidget/GeolocationGooglegeocoderWidget.php
Returns a form to configure settings for the widget.
GeolocationGoogleMapFormatter::settingsForm in src/Plugin/Field/FieldFormatter/GeolocationGoogleMapFormatter.php
Returns a form to configure settings for the formatter.

File

src/GoogleMapsDisplayTrait.php, line 230

Class

GoogleMapsDisplayTrait
Class GoogleMapsDisplayTrait.

Namespace

Drupal\geolocation

Code

public function getGoogleMapsSettingsForm(array $settings, $form_prefix = '') {
  $settings['google_map_settings'] += self::getGoogleMapDefaultSettings()['google_map_settings'];
  $form = [
    'google_map_settings' => [
      '#type' => 'details',
      '#title' => t('Google Maps settings'),
      '#description' => t('Additional map settings provided by Google Maps'),
    ],
  ];

  /*
   * General settings.
   */
  $form['google_map_settings']['general_settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('General'),
  ];
  $form['google_map_settings']['height'] = [
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#type' => 'textfield',
    '#title' => $this
      ->t('Height'),
    '#description' => $this
      ->t('Enter the dimensions and the measurement units. E.g. 200px or 100%.'),
    '#size' => 4,
    '#default_value' => $settings['google_map_settings']['height'],
  ];
  $form['google_map_settings']['width'] = [
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#type' => 'textfield',
    '#title' => $this
      ->t('Width'),
    '#description' => $this
      ->t('Enter the dimensions and the measurement units. E.g. 200px or 100%.'),
    '#size' => 4,
    '#default_value' => $settings['google_map_settings']['width'],
  ];
  $form['google_map_settings']['type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default map type'),
    '#options' => $this
      ->getMapTypes(),
    '#default_value' => $settings['google_map_settings']['type'],
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#process' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'processGroup',
      ],
      [
        '\\Drupal\\Core\\Render\\Element\\Select',
        'processSelect',
      ],
    ],
    '#pre_render' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'preRenderGroup',
      ],
    ],
  ];
  $form['google_map_settings']['zoom'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Zoom level'),
    '#options' => range(static::$MINZOOMLEVEL, static::$MAXZOOMLEVEL),
    '#description' => $this
      ->t('The initial resolution at which to display the map, where zoom 0 corresponds to a map of the Earth fully zoomed out, and higher zoom levels zoom in at a higher resolution.'),
    '#default_value' => $settings['google_map_settings']['zoom'],
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#process' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'processGroup',
      ],
      [
        '\\Drupal\\Core\\Render\\Element\\Select',
        'processSelect',
      ],
    ],
    '#pre_render' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'preRenderGroup',
      ],
    ],
  ];
  $form['google_map_settings']['maxZoom'] = [
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#type' => 'select',
    '#title' => $this
      ->t('Max Zoom level'),
    '#options' => range(static::$MINZOOMLEVEL, static::$MAXZOOMLEVEL),
    '#description' => $this
      ->t('The maximum zoom level which will be displayed on the map. If omitted, or set to null, the maximum zoom from the current map type is used instead.'),
    '#default_value' => $settings['google_map_settings']['maxZoom'],
    '#process' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'processGroup',
      ],
      [
        '\\Drupal\\Core\\Render\\Element\\Select',
        'processSelect',
      ],
    ],
    '#pre_render' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'preRenderGroup',
      ],
    ],
  ];
  $form['google_map_settings']['minZoom'] = [
    '#group' => $form_prefix . 'google_map_settings][general_settings',
    '#type' => 'select',
    '#title' => $this
      ->t('Min Zoom level'),
    '#options' => range(static::$MINZOOMLEVEL, static::$MAXZOOMLEVEL),
    '#description' => $this
      ->t('The minimum zoom level which will be displayed on the map. If omitted, or set to null, the minimum zoom from the current map type is used instead.'),
    '#default_value' => $settings['google_map_settings']['minZoom'],
    '#process' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'processGroup',
      ],
      [
        '\\Drupal\\Core\\Render\\Element\\Select',
        'processSelect',
      ],
    ],
    '#pre_render' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'preRenderGroup',
      ],
    ],
  ];

  /*
   * Control settings.
   */
  $form['google_map_settings']['control_settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Controls'),
  ];
  $form['google_map_settings']['mapTypeControl'] = [
    '#group' => $form_prefix . 'google_map_settings][control_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Map type control'),
    '#description' => $this
      ->t('Allow the user to change the map type.'),
    '#default_value' => $settings['google_map_settings']['mapTypeControl'],
  ];
  $form['google_map_settings']['streetViewControl'] = [
    '#group' => $form_prefix . 'google_map_settings][control_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Street view control'),
    '#description' => $this
      ->t('Allow the user to switch to google street view.'),
    '#default_value' => $settings['google_map_settings']['streetViewControl'],
  ];
  $form['google_map_settings']['zoomControl'] = [
    '#group' => $form_prefix . 'google_map_settings][control_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Zoom control'),
    '#description' => $this
      ->t('Show zoom controls.'),
    '#default_value' => $settings['google_map_settings']['zoomControl'],
  ];
  $form['google_map_settings']['rotateControl'] = [
    '#group' => $form_prefix . 'google_map_settings][control_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Rotate control'),
    '#description' => $this
      ->t('Show rotate control.'),
    '#default_value' => $settings['google_map_settings']['rotateControl'],
  ];
  $form['google_map_settings']['fullscreenControl'] = [
    '#group' => $form_prefix . 'google_map_settings][control_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Fullscreen control'),
    '#description' => $this
      ->t('Show fullscreen control.'),
    '#default_value' => $settings['google_map_settings']['fullscreenControl'],
  ];

  /*
   * Behavior settings.
   */
  $form['google_map_settings']['behavior_settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Behavior'),
  ];
  $form['google_map_settings']['scrollwheel'] = [
    '#group' => $form_prefix . 'google_map_settings][behavior_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Scrollwheel'),
    '#description' => $this
      ->t('Allow the user to zoom the map using the scrollwheel.'),
    '#default_value' => $settings['google_map_settings']['scrollwheel'],
  ];
  $form['google_map_settings']['gestureHandling'] = [
    '#group' => $form_prefix . 'google_map_settings][behavior_settings',
    '#type' => 'select',
    '#title' => $this
      ->t('Gesture Handling'),
    '#default_value' => $settings['google_map_settings']['gestureHandling'],
    '#description' => $this
      ->t('Define how to handle interactions with map on mobile. Read the <a href=":introduction">introduction</a> for handling or the <a href=":details">details</a>, <i>available as of v3.27 / Nov. 2016</i>.', [
      ':introduction' => 'https://googlegeodevelopers.blogspot.de/2016/11/smart-scrolling-comes-to-mobile-web-maps.html',
      ':details' => 'https://developers.google.com/maps/documentation/javascript/3.exp/reference#MapOptions',
    ]),
    '#options' => [
      'auto' => $this
        ->t('auto (default)'),
      'cooperative' => $this
        ->t('cooperative'),
      'greedy' => $this
        ->t('greedy'),
      'none' => $this
        ->t('none'),
    ],
    '#process' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'processGroup',
      ],
      [
        '\\Drupal\\Core\\Render\\Element\\Select',
        'processSelect',
      ],
    ],
    '#pre_render' => [
      [
        '\\Drupal\\Core\\Render\\Element\\RenderElement',
        'preRenderGroup',
      ],
    ],
  ];
  $form['google_map_settings']['draggable'] = [
    '#group' => $form_prefix . 'google_map_settings][behavior_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Draggable'),
    '#description' => $this
      ->t('Allow the user to change the field of view. <i>Deprecated as of v3.27 / Nov. 2016 in favor of gesture handling described above.</i>.'),
    '#default_value' => $settings['google_map_settings']['draggable'],
  ];
  $form['google_map_settings']['preferScrollingToZooming'] = [
    '#group' => $form_prefix . 'google_map_settings][behavior_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Require the user to click the map once to zoom, to ease scrolling behavior.'),
    '#description' => $this
      ->t('Note: this is only relevant, when the Scrollwheel option is enabled.'),
    '#default_value' => $settings['google_map_settings']['preferScrollingToZooming'],
  ];
  $form['google_map_settings']['disableDoubleClickZoom'] = [
    '#group' => $form_prefix . 'google_map_settings][behavior_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable double click zoom'),
    '#description' => $this
      ->t('Disables the double click zoom functionality.'),
    '#default_value' => $settings['google_map_settings']['disableDoubleClickZoom'],
  ];
  $form['google_map_settings']['style'] = [
    '#title' => $this
      ->t('JSON styles'),
    '#type' => 'textarea',
    '#default_value' => $settings['google_map_settings']['style'],
    '#description' => $this
      ->t('A JSON encoded styles array to customize the presentation of the Google Map. See the <a href=":styling">Styled Map</a> section of the Google Maps website for further information.', [
      ':styling' => 'https://developers.google.com/maps/documentation/javascript/styling',
    ]),
  ];

  /*
   * Marker settings.
   */
  $form['google_map_settings']['marker_settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Marker'),
  ];
  $form['google_map_settings']['info_auto_display'] = [
    '#group' => $form_prefix . 'google_map_settings][marker_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Automatically show info text'),
    '#default_value' => $settings['google_map_settings']['info_auto_display'],
  ];
  $form['google_map_settings']['marker_icon_path'] = [
    '#group' => $form_prefix . 'google_map_settings][marker_settings',
    '#type' => 'textfield',
    '#title' => $this
      ->t('Marker icon path'),
    '#description' => $this
      ->t('Set relative or absolute path to custom marker icon. Tokens supported. Empty for default.'),
    '#default_value' => $settings['google_map_settings']['marker_icon_path'],
  ];
  $form['google_map_settings']['disableAutoPan'] = [
    '#group' => $form_prefix . 'google_map_settings][marker_settings',
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable automatic panning of map when info bubble is opened.'),
    '#default_value' => $settings['google_map_settings']['disableAutoPan'],
  ];
  return $form;
}