You are here

private function GeofieldMapFieldTrait::setMapMarkerclusterElement in Geofield Map 8.2

Same name and namespace in other branches
  1. 8 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::setMapMarkerclusterElement()

Set Map Marker Cluster Element.

Parameters

array $settings: The Form Settings.

array $elements: The Form element to alter.

1 call to GeofieldMapFieldTrait::setMapMarkerclusterElement()
GeofieldMapFieldTrait::generateGmapSettingsForm in src/GeofieldMapFieldTrait.php
Generate the Google Map Settings Form.

File

src/GeofieldMapFieldTrait.php, line 1302

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

private function setMapMarkerclusterElement(array $settings, array &$elements) {
  $default_settings = $this::getDefaultSettings();
  $elements['map_markercluster'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Marker Clustering'),
  ];
  $elements['map_markercluster']['markup'] = [
    '#markup' => $this
      ->t('Enable the functionality of the @markeclusterer_api_link.', [
      '@markeclusterer_api_link' => $this->link
        ->generate($this
        ->t('Marker Clusterer Google Maps JavaScript Library'), Url::fromUri('https://github.com/googlemaps/js-marker-clusterer', [
        'absolute' => TRUE,
        'attributes' => [
          'target' => 'blank',
        ],
      ])),
    ]),
  ];
  $elements['map_markercluster']['markercluster_control'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Marker Clustering'),
    '#default_value' => isset($settings['map_markercluster']['markercluster_control']) ? $settings['map_markercluster']['markercluster_control'] : $default_settings['map_markercluster']['markercluster_control'],
    '#return_value' => 1,
  ];
  $elements['map_markercluster']['markercluster_additional_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 Marker Clusterer Google Maps JavaScript 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.<br><u>Hint:</u> it is possible to define the "imagePath" property to point the folder where are stored custom 1.png, 2.png, etc. marker clusters icons, such as: "imagePath":"\\/themes\\/custom\\/THEMENAME\\/images\\/"'),
    '#default_value' => isset($settings['map_markercluster']['markercluster_additional_options']) ? $settings['map_markercluster']['markercluster_additional_options'] : $default_settings['map_markercluster']['markercluster_additional_options'],
    '#placeholder' => '{"maxZoom":12,"gridSize":50}',
    '#element_validate' => [
      [
        get_class($this),
        'jsonValidate',
      ],
    ],
  ];
  $elements['map_markercluster']['markercluster_warning'] = [
    '#type' => 'container',
    'warning' => [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => $this
        ->t('WARNING:') . " ",
      '#attributes' => [
        'class' => [
          'geofield-map-warning',
        ],
      ],
    ],
    'warning_text' => [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => $this
        ->t('Markers Spiderfy is Active ! | A "maxZoom" property should be set in the Marker Cluster Options to output the Spiderfy effect.'),
    ],
  ];
  if (isset($this->fieldDefinition)) {
    $elements['map_markercluster']['markercluster_additional_options']['#states'] = [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][map_markercluster][markercluster_control]"]' => [
          'checked' => TRUE,
        ],
      ],
    ];
    $elements['map_markercluster']['markercluster_warning']['#states'] = [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][map_oms][map_oms_control]"]' => [
          'checked' => TRUE,
        ],
      ],
      'invisible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][map_markercluster][markercluster_control]"]' => [
          'checked' => FALSE,
        ],
      ],
    ];
  }
  else {
    $elements['map_markercluster']['markercluster_additional_options']['#states'] = [
      'visible' => [
        ':input[name="style_options[map_markercluster][markercluster_control]"]' => [
          'checked' => TRUE,
        ],
      ],
    ];
    $elements['map_markercluster']['markercluster_warning']['#states'] = [
      'visible' => [
        ':input[name="style_options[map_oms][map_oms_control]"]' => [
          'checked' => TRUE,
        ],
      ],
      'invisible' => [
        ':input[name="style_options[map_markercluster][markercluster_control]"]' => [
          'checked' => FALSE,
        ],
      ],
    ];
  }
}