You are here

public function FileGeocodeFormatter::settingsForm in Geocoder 8.3

Same name and namespace in other branches
  1. 8.2 modules/geocoder_field/src/Plugin/Field/FieldFormatter/FileGeocodeFormatter.php \Drupal\geocoder_field\Plugin\Field\FieldFormatter\FileGeocodeFormatter::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 GeocodeFormatterBase::settingsForm

1 call to FileGeocodeFormatter::settingsForm()
GeoPhpGeocodeFormatter::settingsForm in modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php
Returns a form to configure settings for the formatter.
1 method overrides FileGeocodeFormatter::settingsForm()
GeoPhpGeocodeFormatter::settingsForm in modules/geocoder_geofield/src/Plugin/Field/FieldFormatter/GeoPhpGeocodeFormatter.php
Returns a form to configure settings for the formatter.

File

modules/geocoder_field/src/Plugin/Field/FieldFormatter/FileGeocodeFormatter.php, line 146

Class

FileGeocodeFormatter
Plugin implementation of the Geocode formatter for File and Image fields.

Namespace

Drupal\geocoder_field\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element['intro'] = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $this->pluginDefinition['description'],
  ];
  $element += parent::settingsForm($form, $form_state);

  // Filter out the Geocoder Plugins that are not compatible with the Geocode
  // Formatter action.
  $compatible_providers = array_filter($element['providers'], function ($e) {
    $geocoder_providers = $this->geocoderProviders;

    /* @var \Drupal\geocoder\Entity\GeocoderProvider $geocoder_provider */
    if (isset($geocoder_providers[$e]) && ($geocoder_provider = $geocoder_providers[$e])) {

      /* @var \Drupal\Component\Plugin\PluginBase $plugin */
      $plugin = $geocoder_provider
        ->getPlugin();
      return $plugin
        ->getPluginId() == $this->formatterPlugin;
    }
    return TRUE;
  }, ARRAY_FILTER_USE_KEY);

  // Generate a warning markup in case of no compatible Geocoder Provider.
  if (count($element['providers']) - count($compatible_providers) == count($this->geocoderProviders)) {
    $element['warning'] = [
      '#markup' => $this
        ->t('Any "@plugin" Geocoder Provider available for this Formatter.', [
        '@plugin' => $this->formatterPlugin,
      ]),
    ];
  }
  $element['providers'] = $compatible_providers;
  return $element;
}