Skip to content
Snippets Groups Projects
Commit 4b316493 authored by Italo Mairo's avatar Italo Mairo
Browse files

tmp update

parent 60f80d1d
No related branches found
Tags tmp
No related merge requests found
......@@ -213,9 +213,19 @@ field.formatter.settings.leaflet_formatter_default:
position:
type: string
label: 'Position'
leaflet_tooltip:
type: mapping
label: 'Tooltip Source'
mapping:
value:
type: string
label: 'Value'
options:
type: text
label: 'Tooltip Options'
popup:
type: boolean
label: 'Popup'
label: 'Leaflet Popup'
popup_content:
type: text
label: 'Popup Content'
......@@ -346,10 +356,16 @@ field.formatter.settings.leaflet_formatter_default:
options:
type: text
label: 'Options'
path:
type: text
label: 'Path'
feature_properties:
type: mapping
label: 'Feature Additional Properties'
mapping:
values:
type: text
label: 'Values'
geocoder:
type: mapping
label: 'Geocoder map control'
......
......@@ -531,8 +531,6 @@ class LeafletMap extends StylePluginBase implements ContainerFactoryPluginInterf
$form["grouping"][0]["field"]["#description"] = $this->t("You may optionally specify a field by which to group the Leaflet Map Features by Overlayers, whose visibility could be managed throughout the Leaflet Map Layers Control.<br>Leave blank to not group");
unset($form["grouping"][0]["rendered_strip"]);
$form_state->set('this_view', $this);
$form["grouping"][0]["field"]['#ajax'] = [
'callback' => __CLASS__ . '::updateGrouping0OverlaysOptionsAjax',
'wrapper' => 'grouping-0-overlays_options-fieldset',
......@@ -735,9 +733,15 @@ class LeafletMap extends StylePluginBase implements ContainerFactoryPluginInterf
// Set Map Geometries Options Element.
$this->setMapPathOptionsElement($form, $this->options);
// Set the Feature Additional Properties Element.
$this->setFeatureAdditionalPropertiesElement($form, $this->options);
// Set Map Geocoder Control Element, if the Geocoder Module exists,
// otherwise output a tip on Geocoder Module Integration.
$this->setGeocoderMapControl($form, $this->options);
unset($form["#pre_render"]);
}
/**
......@@ -1133,6 +1137,14 @@ class LeafletMap extends StylePluginBase implements ContainerFactoryPluginInterf
"\r",
], "", $this->viewsTokenReplace($this->options['icon']['className'], $tokens)) : '';
// Add Feature additional Properties (if present).
if (!empty($this->options['feature_properties']['values'])) {
$feature['properties'] = str_replace([
"\n",
"\r",
], "", $this->viewsTokenReplace($this->options['feature_properties']['values'], $tokens));
}
// Allow modules to adjust the single feature (marker).
$this->moduleHandler->alter('leaflet_views_feature', $feature, $result, $this->view->rowPlugin);
}
......
......@@ -105,6 +105,9 @@ trait LeafletSettingsElementsTrait {
'options' => '{"position":"topleft","pseudoFullscreen":false}',
],
'path' => '{"color":"#3388ff","opacity":"1.0","stroke":true,"weight":3,"fill":"depends","fillColor":"*","fillOpacity":"0.2","radius":"6"}',
'feature_properties' => [
'values' => '',
],
'geocoder' => [
'control' => FALSE,
'settings' => [
......@@ -141,7 +144,7 @@ trait LeafletSettingsElementsTrait {
$elements['leaflet_map'] = [
'#title' => $this->t('Leaflet Map Tiles Layer'),
'#description' => $this->t('Choose the @leaflet_map_tiles Layer to start the Map with (@see hook_leaflet_map_info).', [
'@leaflet_map_tiles' => $this->link->generate("Leaflet Map Tiles", Url::fromUri("https://leafletjs.com/reference.html#tilelayer", ['attributes' => ['target' => 'blank']])),
'@leaflet_map_tiles' => $this->link->generate("Leaflet Js Library Map Tiles", Url::fromUri("https://leafletjs.com/reference.html#tilelayer", ['attributes' => ['target' => 'blank']])),
]),
'#type' => 'select',
'#options' => $leaflet_map_options,
......@@ -767,21 +770,13 @@ trait LeafletSettingsElementsTrait {
* @param array $view_fields
* The view fields.
*/
protected function setTooltipElement(array &$element, array $settings, array $view_fields) {
protected function setTooltipElement(array &$element, array $settings, array $view_fields = []) {
$default_settings = $this::getDefaultSettings();
$element['leaflet_tooltip'] = [
'#type' => 'fieldset',
'#title' => $this->t('Leaflet Tooltip'),
];
$element['leaflet_tooltip']['value'] = [
'#type' => 'select',
'#title' => $this->t('Tooltip Source'),
'#options' => array_merge(['' => ' - None - '], $view_fields),
'#default_value' => $settings['leaflet_tooltip']['value'] ?? $default_settings['leaflet_tooltip']['value'],
'#description' => $this->t("Use this to insert a Leaflet JS Library Tooltip (Feature by Feature)."),
];
if (isset($this->fieldDefinition)) {
$leaflet_tooltip_visibility = [
'invisible' => [
......@@ -796,6 +791,25 @@ trait LeafletSettingsElementsTrait {
],
];
}
if (isset($this->fieldDefinition)) {
$element['leaflet_tooltip']['value'] = [
'#type' => 'textarea',
'#title' => $this->t('Tooltip Source'),
'#default_value' => $settings['leaflet_tooltip']['value'] ?? $default_settings['leaflet_tooltip']['value'],
'#description' => $this->t("Use this to insert a Leaflet JS Library Tooltip (Feature by Feature)."),
];
}
elseif (!empty($view_fields)) {
$element['leaflet_tooltip']['value'] = [
'#type' => 'select',
'#title' => $this->t('Tooltip Source'),
'#options' => array_merge(['' => ' - None - '], $view_fields),
'#default_value' => $settings['leaflet_tooltip']['value'] ?? $default_settings['leaflet_tooltip']['value'],
'#description' => $this->t("Use this to insert a Leaflet JS Library Tooltip (Feature by Feature)."),
];
}
$element['leaflet_tooltip']['options'] = [
'#type' => 'textarea',
'#rows' => 2,
......@@ -847,7 +861,9 @@ trait LeafletSettingsElementsTrait {
'#title' => $this->t('Popup Source'),
'#options' => $popup_options,
'#default_value' => $popup_source ?? $default_settings['leaflet_popup']['value'],
'#description' => $this->t("Use this to insert a Leaflet JS Library Tooltip (Feature by Feature)."),
'#description' => $this->t("Enable and choose content of a @leaflet_popup that will appear on Marker click.", [
'@leaflet_popup' => $this->link->generate("Leaflet Popup", Url::fromUri("https://leafletjs.com/reference.html#tilelayer", ['attributes' => ['target' => 'blank']])),
]),
];
if (isset($this->fieldDefinition)) {
......@@ -888,7 +904,6 @@ trait LeafletSettingsElementsTrait {
],
],
];
}
/**
......@@ -1058,6 +1073,33 @@ trait LeafletSettingsElementsTrait {
}
}
/**
* Set Feature additional Properties Element.
*
* @param array $element
* The Form element to alter.
* @param array $settings
* The Form Settings.
*/
protected function setFeatureAdditionalPropertiesElement(array &$element, array $settings) {
$default_settings = $this::getDefaultSettings();
$element['feature_properties'] = [
'#type' => 'fieldset',
'#title' => $this->t('Feature Additional Properties'),
];
$element['feature_properties']['values'] = [
'#type' => 'textarea',
'#rows' => 3,
'#title' => $this->t('Values'),
'#description' => $this->t('Add additional key/value(s) that will be added in the "properties" index for each Leaflet Map "feature" (in the drupalSettings js object)<br>An object literal of additional values to be added as sequence of "key":"value".<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>This is as advanced functionality, useful to dynamically alter Leaflet Map and each feature representation/behaviour on the basis of its properties.<br>Supports <b>Replacement Patterns</b>'),
'#default_value' => $settings['feature_properties']['values'] ?? $default_settings['feature_properties']['values'],
'#placeholder' => '{"content type":"{{ type }}"}',
'#element_validate' => [[get_class($this), 'jsonValidate']],
];
}
/**
* Set Map Geocoder Control Element.
*
......
......@@ -5,6 +5,7 @@ namespace Drupal\leaflet\Plugin\Field\FieldFormatter;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
......@@ -199,9 +200,13 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
];
}
$this->setTooltipElement($elements, $settings);
$elements['popup'] = [
'#title' => $this->t('Popup Infowindow'),
'#description' => $this->t('Show a Popup Infowindow on Marker click, with custom content.'),
'#title' => $this->t('Leaflet Popup'),
'#description' => $this->t('Enable a @leaflet_popup that will appear on Marker click.', [
'@leaflet_popup' => $this->link->generate("Leaflet Popup", Url::fromUri("https://leafletjs.com/reference.html#tilelayer", ['attributes' => ['target' => 'blank']])),
]),
'#type' => 'checkbox',
'#default_value' => $settings['popup'],
];
......@@ -209,7 +214,7 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
$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.'),
'#description' => $this->t('Define the custom content for the Leaflet Popup. If empty the Content Title will be output.<br>Supports <b>Replacement Patterns</b>.'),
'#default_value' => $settings['popup_content'],
'#states' => [
'visible' => [
......@@ -241,6 +246,9 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
// Set Map Geometries Options Element.
$this->setMapPathOptionsElement($elements, $settings);
// Set the Feature Additional Properties Element.
$this->setFeatureAdditionalPropertiesElement($elements, $settings);
// Set Map Geocoder Control Element, if the Geocoder Module exists,
// otherwise output a tip on Geocoder Module Integration.
$this->setGeocoderMapControl($elements, $settings);
......@@ -419,6 +427,14 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
// Associate dynamic className property (token based) to icon.
$feature['className'] = !empty($settings['className']) ? str_replace(["\n", "\r"], "", $this->token->replace($settings['className'], $tokens)) : '';
// Add Feature additional Properties (if present).
if (!empty($settings['feature_properties']['values'])) {
$feature['properties'] = str_replace([
"\n",
"\r",
], "", $this->token->replace($settings['feature_properties']['values'], $tokens));
}
// Allow modules to adjust the marker.
$this->moduleHandler->alter('leaflet_formatter_feature', $feature, $item, $entity);
$features[] = $feature;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment