public function SimpleGMapFormatter::settingsForm in Simple Google Maps 8
Same name and namespace in other branches
- 3.0.x src/Plugin/Field/FieldFormatter/SimpleGMapFormatter.php \Drupal\simple_gmap\Plugin\Field\FieldFormatter\SimpleGMapFormatter::settingsForm()
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
- src/
Plugin/ Field/ FieldFormatter/ SimpleGMapFormatter.php, line 48
Class
- SimpleGMapFormatter
- Plugin implementation of the 'simple_gmap' formatter.
Namespace
Drupal\simple_gmap\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['embedded_label'] = [
'#type' => 'markup',
'#markup' => '<h3>' . $this
->t('Embedded map') . '</h3>',
];
$elements['include_map'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include embedded dynamic map'),
'#default_value' => $this
->getSetting('include_map'),
];
$elements['include_static_map'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include embedded static map'),
'#default_value' => $this
->getSetting('include_static_map'),
];
$elements['apikey'] = [
'#type' => 'textfield',
'#title' => $this
->t('Google Maps API key'),
'#default_value' => $this
->getSetting('apikey'),
'#description' => $this
->t('Static Maps will not work without an API key. See the <a href="https://developers.google.com/maps/documentation/static-maps" target="_blank">Static Maps API page</a> to learn more and obtain a key.'),
'#states' => [
'visible' => [
":input[name*='include_static_map']" => [
'checked' => TRUE,
],
],
'required' => [
':input[name*="include_static_map"]' => [
'checked' => TRUE,
],
],
],
];
$elements['iframe_width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Width of embedded map'),
'#default_value' => $this
->getSetting('iframe_width'),
'#description' => $this
->t('You can set sizes in px or percent (ex: 600px or 100%). Note that static maps only accept sizes in pixels, without the suffix px (ex: 600).'),
'#size' => 10,
];
$elements['iframe_height'] = [
'#type' => 'textfield',
'#title' => $this
->t('Height of embedded map'),
'#default_value' => $this
->getSetting('iframe_height'),
'#description' => $this
->t('You can set sizes in px or percent (ex: 600px or 100%). Note that static maps only accept sizes in pixels, without the suffix px (ex: 600).'),
'#size' => 10,
];
$elements['iframe_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title of the iframe for embedded map'),
'#default_value' => $this
->getSetting('iframe_title'),
'#description' => $this
->t('The embedded map is in an iframe HTML tag, which should have a title attribute for screen readers (not shown on the page). Use [address] to insert the address text in the title.'),
];
$elements['static_scale'] = [
'#title' => $this
->t('Load Retina sized static image'),
'#type' => 'select',
'#description' => $this
->t('Choose "Yes" to double the width and height of the static image for use on retina displays. (Only applicable to static map)'),
'#options' => [
1 => $this
->t('No'),
2 => $this
->t('Yes'),
],
'#default_value' => (int) $this
->getSetting('static_scale'),
];
$elements['link_label'] = [
'#type' => 'markup',
'#markup' => '<h3>' . $this
->t('Link to map') . '</h3>',
];
$elements['include_link'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include link to map'),
'#default_value' => $this
->getSetting('include_link'),
];
$elements['link_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link text'),
'#default_value' => $this
->getSetting('link_text'),
'#description' => $this
->t("Enter the text to use for the link to the map, or enter 'use_address' (without the quotes) to use the entered address text as the link text"),
];
$elements['generic_label'] = [
'#type' => 'markup',
'#markup' => '<h3>' . $this
->t('General settings') . '</h3>',
];
$elements['zoom_level'] = [
'#type' => 'select',
'#options' => [
1 => $this
->t('1 - Minimum'),
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
14 => $this
->t('14 - Default'),
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => $this
->t('20 - Maximum'),
],
'#title' => $this
->t('Zoom level'),
'#default_value' => $this
->getSetting('zoom_level'),
];
$elements['include_text'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include original address text'),
'#default_value' => $this
->getSetting('include_text'),
];
$elements['map_type'] = [
'#type' => 'select',
'#title' => $this
->t('Map type'),
'#description' => $this
->t('Choose a default map type for embedded and linked maps'),
'#options' => [
'm' => $this
->t('Map'),
'k' => $this
->t('Satellite'),
'h' => $this
->t('Hybrid'),
'p' => $this
->t('Terrain'),
],
'#default_value' => $this
->getSetting('map_type'),
];
$elements['langcode'] = [
'#type' => 'textfield',
'#title' => $this
->t('Language'),
'#default_value' => $this
->getSetting('langcode'),
'#description' => $this
->t("Enter a two-letter language code that Google Maps can recognize, or enter 'page' (without the quotes) to use the current page's language code"),
];
return $elements;
}