You are here

protected function LeafletSettingsElementsTrait::setMapMarkerclusterElement in Leaflet 8

Same name and namespace in other branches
  1. 2.1.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::setMapMarkerclusterElement()
  2. 2.0.x src/LeafletSettingsElementsTrait.php \Drupal\leaflet\LeafletSettingsElementsTrait::setMapMarkerclusterElement()

Set Map MarkerCluster Element.

Parameters

array $element: The Form element to alter.

array $settings: The Form Settings.

2 calls to LeafletSettingsElementsTrait::setMapMarkerclusterElement()
LeafletDefaultFormatter::settingsForm in src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php
Returns a form to configure settings for the formatter.
LeafletMap::buildOptionsForm in modules/leaflet_views/src/Plugin/views/style/LeafletMap.php
Provide a form to edit options for this plugin.

File

src/LeafletSettingsElementsTrait.php, line 674

Class

LeafletSettingsElementsTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\leaflet

Code

protected function setMapMarkerclusterElement(array &$element, array $settings) {
  $default_settings = $this::getDefaultSettings();
  $leaflet_markercluster_submodule_warning = $this
    ->t("<u>Note</u>: This functionality and settings are related to the Leaflet Markercluster submodule, present inside the Leaflet module itself.<br><u>(DON'T USE the external self standing Leaflet Markecluster module).</u>");
  $element['leaflet_markercluster'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Marker Clustering'),
  ];
  if ($this->moduleHandler
    ->moduleExists('leaflet_markercluster')) {
    $element['leaflet_markercluster']['control'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable the functionality of the @markeclusterer_api_link.', [
        '@markeclusterer_api_link' => $this->link
          ->generate($this
          ->t('Leaflet Markercluster Js Library'), Url::fromUri('https://github.com/Leaflet/Leaflet.markercluster', [
          'absolute' => TRUE,
          'attributes' => [
            'target' => 'blank',
          ],
        ])),
      ]),
      '#default_value' => isset($settings['leaflet_markercluster']['control']) ? $settings['leaflet_markercluster']['control'] : $default_settings['leaflet_markercluster']['control'],
      '#description' => $this
        ->t("@leaflet_markercluster_submodule_warning", [
        '@leaflet_markercluster_submodule_warning' => $leaflet_markercluster_submodule_warning,
      ]),
      '#return_value' => 1,
    ];
    $element['leaflet_markercluster']['options'] = [
      '#type' => 'textarea',
      '#rows' => 4,
      '#title' => $this
        ->t('Marker Cluster Additional Options'),
      '#description' => $this
        ->t('An object literal of additional marker cluster options, that comply with the Leaflet Markercluster Js Library.<br>The syntax should respect the javascript object notation (json) format.<br>As suggested in the field placeholder, always use double quotes (") both for the indexes and the string values.'),
      '#default_value' => isset($settings['leaflet_markercluster']['options']) ? $settings['leaflet_markercluster']['options'] : $default_settings['leaflet_markercluster']['options'],
      '#placeholder' => $default_settings['leaflet_markercluster']['options'],
      '#element_validate' => [
        [
          get_class($this),
          'jsonValidate',
        ],
      ],
    ];
    if (isset($this->fieldDefinition)) {
      $element['leaflet_markercluster']['options']['#states'] = [
        'visible' => [
          ':input[name="fields[' . $this->fieldDefinition
            ->getName() . '][settings_edit_form][settings][leaflet_markercluster][control]"]' => [
            'checked' => TRUE,
          ],
        ],
      ];
    }
    else {
      $element['leaflet_markercluster']['options']['#states'] = [
        'visible' => [
          ':input[name="style_options[leaflet_markercluster][control]"]' => [
            'checked' => TRUE,
          ],
        ],
      ];
    }
  }
  else {
    $element['leaflet_markercluster']['markup'] = [
      '#markup' => $this
        ->t("Enable the Leaflet Markecluster submodule to activate this functionality.<br>@leaflet_markercluster_submodule_warning", [
        '@leaflet_markercluster_submodule_warning' => $leaflet_markercluster_submodule_warning,
      ]),
    ];
  }
}