You are here

public function LeafletDefaultFormatter::settingsForm in Leaflet 2.1.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php \Drupal\leaflet\Plugin\Field\FieldFormatter\LeafletDefaultFormatter::settingsForm()
  2. 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 172

Class

LeafletDefaultFormatter
Plugin implementation of the 'leaflet_default' formatter.

Namespace

Drupal\leaflet\Plugin\Field\FieldFormatter

Code

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();

  // Set Replacement Patterns Element.
  $this
    ->setReplacementPatternsElement($elements);
  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 the Leaflet Map weight/zIndex Form Element.
  $elements['weight'] = $this
    ->generateWeightElement($settings['weight']);

  // Generate Icon form element.
  $icon_options = $settings['icon'];
  $elements['icon'] = $this
    ->generateIconFormElement($icon_options);

  // 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;
}