diff --git a/config/schema/geolocation.field.schema.yml b/config/schema/geolocation.field.schema.yml index 6d3dbad..aed70bc 100644 --- a/config/schema/geolocation.field.schema.yml +++ b/config/schema/geolocation.field.schema.yml @@ -12,7 +12,7 @@ field.formatter.settings.geolocation_map: type: string label: 'Title' info_text: - type: string + type: text_format label: 'Info Text' use_overridden_map_settings: type: integer @@ -23,7 +23,7 @@ field.formatter.settings.geolocation_token: label: 'Geolocation Token Formatter' mapping: tokenized_text: - type: string + type: text_format label: 'Tokenized text' geolocation.field.widget.map: diff --git a/js/geolocation-common-map.js b/js/geolocation-common-map.js index 7573288..de3dd34 100644 --- a/js/geolocation-common-map.js +++ b/js/geolocation-common-map.js @@ -55,6 +55,10 @@ var map = Drupal.geolocation.getMapById(mapId); + if (!map) { + return; + } + /* * Hide form if requested. */ @@ -82,6 +86,7 @@ typeof commonMapSettings.markerScrollToResult !== 'undefined' && commonMapSettings.markerScrollToResult === true ) { + map.addLoadedCallback(function (map) { $.each(map.mapMarkers, function (index, marker) { marker.addListener('click', function () { diff --git a/modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml b/modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml index fcb7221..829d74e 100644 --- a/modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml +++ b/modules/geolocation_google_maps/config/schema/geolocation_google_maps.map_features.schema.yml @@ -76,7 +76,7 @@ plugin.plugin_configuration.geolocation.map_feature.context_popup: label: 'Settings' mapping: content: - type: string + type: text_format label: 'Content' geolocation_google_maps.map_control_feature_settings: diff --git a/modules/geolocation_google_maps/js/MapFeature/geolocation-control-maptype.js b/modules/geolocation_google_maps/js/MapFeature/geolocation-control-maptype.js index 3d56d4b..1cb394a 100644 --- a/modules/geolocation_google_maps/js/MapFeature/geolocation-control-maptype.js +++ b/modules/geolocation_google_maps/js/MapFeature/geolocation-control-maptype.js @@ -35,6 +35,10 @@ ) { var map = Drupal.geolocation.getMapById(mapId); + if (!map) { + return; + } + map.addLoadedCallback(function (map) { var options = { mapTypeControlOptions: { diff --git a/modules/geolocation_google_maps/js/MapFeature/geolocation-control-streetview.js b/modules/geolocation_google_maps/js/MapFeature/geolocation-control-streetview.js index 15971f1..3873716 100644 --- a/modules/geolocation_google_maps/js/MapFeature/geolocation-control-streetview.js +++ b/modules/geolocation_google_maps/js/MapFeature/geolocation-control-streetview.js @@ -34,6 +34,10 @@ ) { var map = Drupal.geolocation.getMapById(mapId); + if (!map) { + return; + } + map.addLoadedCallback(function (map) { var options = { streetViewControlOptions: { diff --git a/modules/geolocation_google_maps/js/MapFeature/geolocation-marker-infobubble.js b/modules/geolocation_google_maps/js/MapFeature/geolocation-marker-infobubble.js index ce081a5..d128041 100644 --- a/modules/geolocation_google_maps/js/MapFeature/geolocation-marker-infobubble.js +++ b/modules/geolocation_google_maps/js/MapFeature/geolocation-marker-infobubble.js @@ -50,7 +50,7 @@ 'use strict'; /** - * CMarker InfoBubble. + * Marker InfoBubble. * * @type {Drupal~behavior} * @@ -80,7 +80,6 @@ } map.addMarkerAddedCallback(function (currentMarker) { - console.log('Adding infoBubble to marker'); var content = currentMarker.locationWrapper.find('.location-content').html(); if (content.length < 1) { diff --git a/modules/geolocation_google_maps/js/MapFeature/geolocation-markerclusterer.js b/modules/geolocation_google_maps/js/MapFeature/geolocation-markerclusterer.js index 8682165..2f1ac7a 100644 --- a/modules/geolocation_google_maps/js/MapFeature/geolocation-markerclusterer.js +++ b/modules/geolocation_google_maps/js/MapFeature/geolocation-markerclusterer.js @@ -60,7 +60,6 @@ map.addReadyCallback(function (map) { if (typeof map.markerClusterer === 'undefined') { - console.log("MarkerClusterer added"); map.markerClusterer = new MarkerClusterer( map.googleMap, [], @@ -73,8 +72,6 @@ } map.addMarkerAddedCallback(function (marker) { - console.log("Adding marker to cluster"); - map.markerClusterer.addMarker(marker); }); diff --git a/modules/geolocation_google_maps/js/geolocation-common-map-google.js b/modules/geolocation_google_maps/js/geolocation-common-map-google.js index 85aba73..2f1d8b6 100644 --- a/modules/geolocation_google_maps/js/geolocation-common-map-google.js +++ b/modules/geolocation_google_maps/js/geolocation-common-map-google.js @@ -25,6 +25,10 @@ ) { var map = Drupal.geolocation.getMapById(mapId); + if (!map) { + return; + } + /** * Update the view depending on dynamic map settings and capability. * @@ -46,6 +50,7 @@ && !map.container.hasClass('geolocation-common-map-google-processed') ) { map.container.addClass('geolocation-common-map-google-processed'); + map.addLoadedCallback(function (map) { var geolocationMapIdleTimer; map.googleMap.addListener('bounds_changed', function () { diff --git a/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ContextPopup.php b/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ContextPopup.php index 239fa0c..b76aabe 100644 --- a/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ContextPopup.php +++ b/modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ContextPopup.php @@ -22,7 +22,10 @@ class ContextPopup extends MapFeatureBase { */ public static function getDefaultSettings() { return [ - 'content' => '', + 'content' => [ + 'value' => '', + 'format' => '', + ], ]; } @@ -31,11 +34,14 @@ class ContextPopup extends MapFeatureBase { */ public function getSettingsForm(array $settings, array $parents) { $settings = $this->getSettings($settings); + + $form = parent::getSettingsForm($settings, $parents); $form['content'] = [ - '#type' => 'textarea', + '#type' => 'text_format', '#title' => $this->t('Context popup content'), '#description' => $this->t('A right click on the map will open a context popup with this content. Tokens supported. Additionally "@lat, @lng" will be replaced dynamically.'), - '#default_value' => $settings['content'], + '#default_value' => $settings['content']['value'], + '#format' => $settings['content']['format'], ]; return $form; @@ -49,12 +55,12 @@ class ContextPopup extends MapFeatureBase { $feature_settings = $this->getSettings($feature_settings); - $data = []; + $token_context = []; if (!empty($context['view'])) { - $data['view'] = $context['view']; + $token_context['view'] = $context['view']; } - $content = \Drupal::token()->replace($feature_settings['content'], $data); + $content = check_markup(\Drupal::token()->replace($feature_settings['content']['value'], $token_context), $feature_settings['content']['format']); $render_array['#attached'] = BubbleableMetadata::mergeAttachments( empty($render_array['#attached']) ? [] : $render_array['#attached'], diff --git a/src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php b/src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php index 48864a4..3fc1aa7 100644 --- a/src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php +++ b/src/Plugin/Field/FieldFormatter/GeolocationMapFormatterBase.php @@ -60,7 +60,10 @@ abstract class GeolocationMapFormatterBase extends FormatterBase { $settings['title'] = ''; $settings['set_marker'] = TRUE; $settings['common_map'] = TRUE; - $settings['info_text'] = ''; + $settings['info_text'] = [ + 'value' => '', + 'format' => '', + ]; $settings += parent::defaultSettings(); $settings['use_overridden_map_settings'] = FALSE; @@ -106,10 +109,11 @@ abstract class GeolocationMapFormatterBase extends FormatterBase { ]; $form['info_text'] = [ - '#type' => 'textarea', + '#type' => 'text_format', '#title' => $this->t('Marker info text'), '#description' => $this->t('When the marker is clicked, this text will be shown in a popup above it. Leave blank to not display. Token replacement supported.'), - '#default_value' => $settings['info_text'], + '#default_value' => $settings['info_text']['value'], + '#format' => $settings['info_text']['format'], '#states' => [ 'visible' => [ ':input[name="fields[' . $this->fieldDefinition->getName() . '][settings_edit_form][settings][set_marker]"]' => ['checked' => TRUE], @@ -170,7 +174,7 @@ abstract class GeolocationMapFormatterBase extends FormatterBase { if ($settings['set_marker']) { $summary[] = $this->t('Marker Title: @type', ['@type' => $settings['title']]); $summary[] = $this->t('Marker Info Text: @type', [ - '@type' => current(explode(chr(10), wordwrap($settings['info_text'], 30))), + '@type' => current(explode(chr(10), wordwrap(check_markup($settings['info_text']['value'], $settings['info_text']['format']), 30))), ]); if (!empty($settings['common_map'])) { $summary[] = $this->t('Common Map Display: Yes'); @@ -210,16 +214,20 @@ abstract class GeolocationMapFormatterBase extends FormatterBase { if (empty($title)) { $title = $item->lat . ', ' . $item->lng; } - $content = \Drupal::token() - ->replace($settings['info_text'], $token_context, [ - 'callback' => [$this, 'geolocationItemTokens'], - 'clear' => TRUE, - ]); $location = [ '#type' => 'geolocation_map_location', 'content' => [ - '#markup' => $content, + '#type' => 'processed_text', + '#text' => \Drupal::token()->replace( + $settings['info_text']['value'], + $token_context, + [ + 'callback' => [$this, 'geolocationItemTokens'], + 'clear' => TRUE, + ] + ), + '#format' => $settings['info_text']['format'], ], '#title' => $title, '#disable_marker' => empty($settings['set_marker']) ? TRUE : FALSE, diff --git a/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php b/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php index 6748ed2..9b45f12 100644 --- a/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php +++ b/src/Plugin/Field/FieldFormatter/GeolocationTokenFormatter.php @@ -29,7 +29,10 @@ class GeolocationTokenFormatter extends FormatterBase { */ public static function defaultSettings() { $settings = []; - $settings['tokenized_text'] = ''; + $settings['tokenized_text'] = [ + 'value' => '', + 'format' => '', + ]; $settings += parent::defaultSettings(); return $settings; @@ -42,10 +45,11 @@ class GeolocationTokenFormatter extends FormatterBase { $settings = $this->getSettings(); $element['tokenized_text'] = [ - '#type' => 'textarea', + '#type' => 'text_format', '#title' => $this->t('Tokenized text'), '#description' => $this->t('Enter any text or HTML to be shown for each value. Tokens will be replaced as available. The "token" module greatly expands the number of available tokens as well as provides a comfortable token browser.'), - '#default_value' => $settings['tokenized_text'], + '#default_value' => $settings['tokenized_text']['value'], + '#format' => $settings['tokenized_text']['format'], ]; $element['token_help'] = $this->getTokenHelp(); @@ -62,7 +66,7 @@ class GeolocationTokenFormatter extends FormatterBase { $summary = []; $summary[] = $this->t('Tokenized Text: %text', [ '%text' => Unicode::truncate( - $settings['tokenized_text'], + check_markup($settings['tokenized_text']['value'], $settings['tokenized_text']['format']), 100, TRUE, TRUE @@ -83,12 +87,20 @@ class GeolocationTokenFormatter extends FormatterBase { $elements = []; foreach ($items as $delta => $item) { $token_context['geolocation_current_item'] = $item; - $tokenized_text = \Drupal::token()->replace($this->getSetting('tokenized_text'), $token_context, [ - 'callback' => [$this, 'geolocationItemTokens'], - 'clear' => TRUE, - ]); + + $tokenized_text = $this->getSetting('tokenized_text'); + $elements[$delta] = [ - '#markup' => $tokenized_text, + '#type' => 'processed_text', + '#text' => \Drupal::token()->replace( + $tokenized_text['value'], + $token_context, + [ + 'callback' => [$this, 'geolocationItemTokens'], + 'clear' => TRUE, + ] + ), + '#format' => $tokenized_text['format'], ]; }