You are here

private function GeofieldMapFieldTrait::setMapMarkerclusterElement in Geofield Map 8

Same name and namespace in other branches
  1. 8.2 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 1040

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

private function setMapMarkerclusterElement(array $settings, array &$elements) {
  $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' => $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.'),
    '#default_value' => $settings['map_markercluster']['markercluster_additional_options'],
    '#placeholder' => '{"maxZoom": 12, "gridSize": 25, "imagePath": "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png"}',
    '#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 ! | If not, a "maxZoom" property should be set in the Marker Cluster Additional Options to be able to output the Spederfy 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,
        ],
      ],
    ];
  }
}