public function GeolocationGooglegeocoderWidget::settingsForm in Geolocation Field 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.
Overrides WidgetBase::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ GeolocationGooglegeocoderWidget.php, line 121
Class
- GeolocationGooglegeocoderWidget
- Plugin implementation of the 'geolocation_googlegeocoder' widget.
Namespace
Drupal\geolocation\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$settings = $this
->getSettings();
$element = [];
$element['default_longitude'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default Longitude'),
'#description' => $this
->t('The default center point, before a value is set.'),
'#default_value' => $settings['default_longitude'],
];
$element['default_latitude'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default Latitude'),
'#description' => $this
->t('The default center point, before a value is set.'),
'#default_value' => $settings['default_latitude'],
];
$element['auto_client_location'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically use client location, when no value is set'),
'#default_value' => $settings['auto_client_location'],
];
$element['auto_client_location_marker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically set marker to client location as well'),
'#default_value' => $settings['auto_client_location_marker'],
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][auto_client_location]"]' => [
'checked' => TRUE,
],
],
],
];
/** @var \Drupal\Core\Field\FieldDefinitionInterface[] $field_definitions */
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($this->fieldDefinition
->getTargetEntityTypeId(), $this->fieldDefinition
->getTargetBundle());
$address_fields = [];
foreach ($field_definitions as $field_definition) {
if ($field_definition
->getType() == 'address' && $field_definition
->getFieldStorageDefinition()
->getCardinality() == 1) {
$address_fields[$field_definition
->getName()] = $field_definition
->getLabel();
}
}
if (!empty($address_fields)) {
$element['populate_address_field'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically push retrieved address data to address field widget'),
'#default_value' => $settings['populate_address_field'],
];
$element['target_address_field'] = [
'#type' => 'select',
'#title' => $this
->t('Select target field to append address data.'),
'#description' => $this
->t('Only fields of type "address" with a cardinality of 1 are available.'),
'#options' => $address_fields,
'#default_value' => $settings['target_address_field'],
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][populate_address_field]"]' => [
'checked' => TRUE,
],
],
],
];
$element['explicite_actions_address_field'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use explicit push/locate buttons to interact with address field widget'),
'#default_value' => $settings['explicite_actions_address_field'],
'#states' => [
'visible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][populate_address_field]"]' => [
'checked' => TRUE,
],
],
],
];
}
$element['allow_override_map_settings'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow override the map settings when create/edit an content.'),
'#default_value' => $settings['allow_override_map_settings'],
];
$element += $this
->getGoogleMapsSettingsForm($settings, 'fields][' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][');
return $element;
}