public function GeofieldGoogleEmbedMapFormatter::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/ GeofieldGoogleEmbedMapFormatter.php, line 128
Class
- GeofieldGoogleEmbedMapFormatter
- Plugin implementation of the 'geofield_embed_google_map' formatter.
Namespace
Drupal\geofield_map_extras\Plugin\Field\FieldFormatterCode
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['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['optionals_parameters'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => $this
->t('Optional parameters'),
'#default_value' => $settings['optionals_parameters'],
'#description' => $this
->t('An object literal of options, that comply with the <strong>Google Maps Embed API Library</strong> (@see link above).<br>The syntax should respect the javascript object notation (json) format.<br>Always use double quotes (") both for the indexes and the string values.'),
'#placeholder' => self::defaultSettings()['optionals_parameters'],
'#element_validate' => [
[
get_class($this),
'jsonValidate',
],
],
];
return $elements;
}