You are here

public function GeofieldGoogleStaticMapFormatter::settingsForm in Geofield Map 8.2

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

modules/geofield_map_extras/src/Plugin/Field/FieldFormatter/GeofieldGoogleStaticMapFormatter.php, line 119

Class

GeofieldGoogleStaticMapFormatter
Plugin implementation of the 'geofield_static_google_map' formatter.

Namespace

Drupal\geofield_map_extras\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = [];
  $settings = $this
    ->getSettings();
  $elements['intro'] = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $this
      ->getFormatterIntro(),
  ];

  // Set Google Api Key Element.
  $elements['map_google_api_key'] = $this
    ->setMapGoogleApiKeyElement();
  $elements['gmaps_api_link_markup'] = [
    '#markup' => $this
      ->t('The following settings comply with the @gmaps_api_link.', [
      '@gmaps_api_link' => $this->link
        ->generate($this
        ->t('Google Maps Static API'), Url::fromUri('https://developers.google.com/maps/documentation/maps-static/dev-guide#introduction', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  $elements['width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Map width'),
    '#default_value' => $settings['width'],
    '#size' => 10,
    '#min' => 1,
    '#step' => 1,
    '#description' => $this
      ->t('The width of the map, in pixels.'),
    '#required' => TRUE,
  ];
  $elements['height'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Map height'),
    '#default_value' => $settings['height'],
    '#size' => 10,
    '#min' => 1,
    '#step' => 1,
    '#description' => $this
      ->t('The height of the map, in pixels.'),
    '#required' => TRUE,
  ];
  $elements['scale'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Scale'),
    '#default_value' => $settings['scale'],
    '#options' => [
      '1' => '1',
      '2' => '2',
      '4' => '4',
    ],
    '#description' => $this
      ->t('The size of the image will be multiplied by this factor, which is useful for ensuring retina-capable displays show the correct size.<br>Note that maximum size restrictions exist in Google Static Maps API.<br>Refer to the @image_sizes_link if you are unsure what values to use here.', [
      ':doc_url' => 'https://developers.google.com/maps/documentation/maps-static/dev-guide#Imagesizes',
      '@image_sizes_link' => $this->link
        ->generate($this
        ->t('Image Sizes documentation'), Url::fromUri('https://developers.google.com/maps/documentation/maps-static/dev-guide#Imagesizes', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  $elements['zoom'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Map zoom'),
    '#default_value' => $settings['zoom'],
    '#size' => 10,
    '#min' => 1,
    '#step' => 1,
    '#max' => 20,
    '#description' => $this
      ->t("The zoom level. Must be an integer between 1 and 20.<br>Note: This will be ignored in case of multiple markers, and the map will extend to markers bounds.."),
    '#required' => TRUE,
  ];
  $elements['static_map_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Map type'),
    '#default_value' => $settings['static_map_type'],
    '#options' => $this
      ->getStaticMapOptions(),
  ];
  $elements['marker_color'] = [
    '#type' => 'color',
    '#title' => $this
      ->t('Marker Color'),
    '#default_value' => $settings['marker_color'],
    '#description' => $this
      ->t("Accepts an HEX cod color.<br>Examples: #ff0000 (red), #00ff00 (green), #0000ff (blu).<br>Leave empty for default value fallback (red).<br>The value wiil be converted to comply with Google @marker_styles_link.", [
      '@marker_styles_link' => $this->link
        ->generate($this
        ->t('Marker Styles documentation'), Url::fromUri('https://developers.google.com/maps/documentation/maps-static/dev-guide#MarkerStyles', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  $elements['marker_size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Marker Size'),
    '#default_value' => $settings['marker_size'],
    '#options' => [
      'normal' => $this
        ->t('normal'),
      'tiny' => $this
        ->t('tiny'),
      'mid' => $this
        ->t('mid'),
      'small' => $this
        ->t('small'),
    ],
    '#description' => $this
      ->t("Refer to the @marker_styles_link if you are unsure what values to use here", [
      '@marker_styles_link' => $this->link
        ->generate($this
        ->t('Marker Styles documentation'), Url::fromUri('https://developers.google.com/maps/documentation/maps-static/dev-guide#MarkerStyles', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  return $elements;
}