You are here

public function GeolocationGoogleMapFormatter::settingsForm in Geolocation Field 8

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/GeolocationGoogleMapFormatter.php, line 49

Class

GeolocationGoogleMapFormatter
Plugin implementation of the 'geolocation_googlemap' formatter.

Namespace

Drupal\geolocation\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $settings = $this
    ->getSettings();
  $element['set_marker'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Set map marker'),
    '#description' => $this
      ->t('The map will be centered on the stored location. Additionally a marker can be set at the exact location.'),
    '#default_value' => $settings['set_marker'],
  ];
  $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'],
      '#states' => [
        'visible' => [
          ':input[name="fields[' . $this->fieldDefinition
            ->getName() . '][settings_edit_form][settings][set_marker]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
  }
  $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' => 'textarea',
    '#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.'),
    '#default_value' => $settings['info_text'],
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][set_marker]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['replacement_patterns'] = [
    '#type' => 'details',
    '#title' => 'Replacement patterns',
    '#description' => $this
      ->t('The following replacement patterns are available for the "Info text" and the "Hover title" settings.'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][set_marker]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['replacement_patterns']['token_geolocation'] = $this
    ->getTokenHelp();
  $element += $this
    ->getGoogleMapsSettingsForm($settings, 'fields][' . $this->fieldDefinition
    ->getName() . '][settings_edit_form][settings][');
  $element['use_overridden_map_settings'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use custom map settings if provided'),
    '#description' => $this
      ->t('The Geolocation GoogleGeocoder widget optionally allows to define custom map settings to use here.'),
    '#default_value' => $settings['use_overridden_map_settings'],
  ];
  return $element;
}