public function LeafletDefaultFormatter::settingsForm in Leaflet 8
Same name and namespace in other branches
- 2.1.x src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php \Drupal\leaflet\Plugin\Field\FieldFormatter\LeafletDefaultFormatter::settingsForm()
- 2.0.x src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php \Drupal\leaflet\Plugin\Field\FieldFormatter\LeafletDefaultFormatter::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/ LeafletDefaultFormatter.php, line 173
Class
- LeafletDefaultFormatter
- Plugin implementation of the 'leaflet_default' formatter.
Namespace
Drupal\leaflet\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$settings = $this
->getSettings();
$form['#tree'] = TRUE;
// Get the Cardinality set for the Formatter Field.
$field_cardinality = $this->fieldDefinition
->getFieldStorageDefinition()
->getCardinality();
$elements = parent::settingsForm($form, $form_state);
$field_name = $this->fieldDefinition
->getName();
if ($this->moduleHandler
->moduleExists('token')) {
$elements['replacement_patterns'] = [
'#type' => 'details',
'#title' => 'Replacement patterns',
'#description' => $this
->t('The following replacement tokens are available for the "Popup Content and the Icon Options":'),
];
$elements['replacement_patterns']['token_help'] = [
'#theme' => 'token_tree_link',
'#token_types' => [
$this->fieldDefinition
->getTargetEntityTypeId(),
],
];
}
else {
$elements['replacement_patterns']['#description'] = $this
->t('The @token_link is needed to browse and use @entity_type entity token replacements.', [
'@token_link' => $this->link
->generate(t('Token module'), Url::fromUri('https://www.drupal.org/project/token', [
'absolute' => TRUE,
'attributes' => [
'target' => 'blank',
],
])),
'@entity_type' => $this->fieldDefinition
->getTargetEntityTypeId(),
]);
}
if ($field_cardinality !== 1) {
$elements['multiple_map'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Multiple Maps'),
'#description' => $this
->t('Check this option if you want to render a single Map for every single Geo Point.'),
'#default_value' => $settings['multiple_map'],
'#return_value' => 1,
];
}
else {
$elements['multiple_map'] = [
'#type' => 'hidden',
'#value' => 0,
];
}
$elements['popup'] = [
'#title' => $this
->t('Popup Infowindow'),
'#description' => $this
->t('Show a Popup Infowindow on Marker click, with custom content.'),
'#type' => 'checkbox',
'#default_value' => $settings['popup'],
];
$elements['popup_content'] = [
'#type' => 'textarea',
'#title' => $this
->t('Popup content'),
'#description' => $this
->t('Define the custom content for the Pop Infowindow. If empty the Content Title will be output.<br>See "REPLACEMENT PATTERNS" above for available replacements.'),
'#default_value' => $settings['popup_content'],
'#states' => [
'visible' => [
'input[name="fields[' . $field_name . '][settings_edit_form][settings][popup]"]' => [
'checked' => TRUE,
],
],
],
];
// Generate the Leaflet Map General Settings.
$this
->generateMapGeneralSettings($elements, $settings);
// Generate the Leaflet Map Reset Control.
$this
->setResetMapControl($elements, $settings);
// Generate the Leaflet Map Position Form Element.
$map_position_options = $settings['map_position'];
$elements['map_position'] = $this
->generateMapPositionElement($map_position_options);
// Generate Icon form element.
$icon_options = $settings['icon'];
$elements['icon'] = $this
->generateIconFormElement($icon_options, $form);
// Set Map Marker Cluster Element.
$this
->setMapMarkerclusterElement($elements, $settings);
// Set Map Geometries Options Element.
$this
->setMapPathOptionsElement($elements, $settings);
// Set Map Geocoder Control Element, if the Geocoder Module exists,
// otherwise output a tip on Geocoder Module Integration.
$this
->setGeocoderMapControl($elements, $settings);
return $elements;
}