public function GeolocationMapFormatterBase::settingsForm in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php \Drupal\geolocation\Plugin\Field\FieldFormatter\GeolocationMapFormatterBase::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
2 calls to GeolocationMapFormatterBase::settingsForm()
- GeolocationGeometryMapFormatter::settingsForm in modules/
geolocation_geometry/ src/ Plugin/ Field/ FieldFormatter/ GeolocationGeometryMapFormatter.php - Returns a form to configure settings for the formatter.
- GeolocationGpxMapFormatter::settingsForm in modules/
geolocation_gpx/ src/ Plugin/ Field/ FieldFormatter/ GeolocationGpxMapFormatter.php - Returns a form to configure settings for the formatter.
2 methods override GeolocationMapFormatterBase::settingsForm()
- GeolocationGeometryMapFormatter::settingsForm in modules/
geolocation_geometry/ src/ Plugin/ Field/ FieldFormatter/ GeolocationGeometryMapFormatter.php - Returns a form to configure settings for the formatter.
- GeolocationGpxMapFormatter::settingsForm in modules/
geolocation_gpx/ src/ Plugin/ Field/ FieldFormatter/ GeolocationGpxMapFormatter.php - Returns a form to configure settings for the formatter.
File
- src/
Plugin/ Field/ FieldFormatter/ GeolocationMapFormatterBase.php, line 116
Class
- GeolocationMapFormatterBase
- Plugin base for Map based formatters.
Namespace
Drupal\geolocation\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$map_provider_options = $this->mapProviderManager
->getMapProviderOptions();
if (empty($map_provider_options)) {
return [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this
->t("No map provider found."),
];
}
$settings = $this
->getSettings();
$element = [];
$data_provider_settings_form = $this->dataProvider
->getSettingsForm($settings['data_provider_settings'], []);
if (!empty($data_provider_settings_form)) {
$element['data_provider_settings'] = $data_provider_settings_form;
}
$element['set_marker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Set map marker'),
'#default_value' => $settings['set_marker'],
];
$element['show_label'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show label'),
'#default_value' => $settings['show_label'],
];
$element['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Marker title'),
'#description' => $this
->t('When the cursor hovers on the marker, this title will be shown as description.'),
'#default_value' => $settings['title'],
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][set_marker]"]' => [
'checked' => TRUE,
],
],
],
];
$element['info_text'] = [
'#type' => 'text_format',
'#title' => $this
->t('Marker info text'),
'#description' => $this
->t('When the marker is clicked, this text will be shown in a popup above it. Leave blank to not display. Token replacement supported.'),
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][set_marker]"]' => [
'checked' => TRUE,
],
],
],
];
if (!empty($settings['info_text']['value'])) {
$element['info_text']['#default_value'] = $settings['info_text']['value'];
}
if (!empty($settings['info_text']['format'])) {
$element['info_text']['#format'] = $settings['info_text']['format'];
}
$element['replacement_patterns'] = [
'#type' => 'details',
'#title' => 'Replacement patterns',
'#description' => $this
->t('The following replacement patterns are available.'),
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][set_marker]"]' => [
'checked' => TRUE,
],
],
],
];
$element['replacement_patterns']['token_geolocation'] = $this->dataProvider
->getTokenHelp();
$cardinality = $this->fieldDefinition
->getFieldStorageDefinition()
->getCardinality();
if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || $cardinality > 1) {
$element['common_map'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display multiple values on a common map'),
'#description' => $this
->t('By default, each value will be displayed in a separate map. Settings this option displays all values on a common map instead. This settings is only useful on multi-value fields.'),
'#default_value' => $settings['common_map'],
];
$element['show_delta_label'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show item cardinality as marker label'),
'#description' => $this
->t('By default markers will not have labels, if shown on the common map it might be useful for AODA to show cardinality'),
'#default_value' => $settings['show_delta_label'],
];
}
$element['centre'] = $this->mapCenterManager
->getCenterOptionsForm((array) $settings['centre'], [
'formatter' => $this,
]);
$element['map_provider_id'] = [
'#type' => 'select',
'#options' => $map_provider_options,
'#title' => $this
->t('Map Provider'),
'#default_value' => $settings['map_provider_id'],
'#ajax' => [
'callback' => [
get_class($this->mapProviderManager),
'addSettingsFormAjax',
],
'wrapper' => 'map-provider-settings',
'effect' => 'fade',
],
];
$element['map_provider_settings'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this
->t("No settings available."),
];
$parents = [
'fields',
$this->fieldDefinition
->getName(),
'settings_edit_form',
'settings',
];
$map_provider_id = NestedArray::getValue($form_state
->getUserInput(), array_merge($parents, [
'map_provider_id',
]));
if (empty($map_provider_id)) {
$map_provider_id = $settings['map_provider_id'];
}
if (empty($map_provider_id)) {
$map_provider_id = key($map_provider_options);
}
$map_provider_settings = NestedArray::getValue($form_state
->getUserInput(), array_merge($parents, [
'map_provider_settings',
]));
if (empty($map_provider_settings)) {
$map_provider_settings = $settings['map_provider_settings'];
}
if (!empty($map_provider_id)) {
$element['map_provider_settings'] = $this->mapProviderManager
->createInstance($map_provider_id, $map_provider_settings)
->getSettingsForm($map_provider_settings, array_merge($parents, [
'map_provider_settings',
]));
}
$element['map_provider_settings'] = array_replace($element['map_provider_settings'], [
'#prefix' => '<div id="map-provider-settings">',
'#suffix' => '</div>',
]);
$element['use_overridden_map_settings'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use custom map settings if provided'),
'#description' => $this
->t('The field map widget optionally allows to define custom map settings to use here.'),
'#default_value' => $settings['use_overridden_map_settings'],
];
return $element;
}