class CustomIconThemer in Geofield Map 8.2
Style plugin to render a View output as a Leaflet map.
Attributes set below end up in the $this->definition[] array.
Plugin annotation
@MapThemer(
id = "geofieldmap_custom_icon",
name = @Translation("Custom Icon Image File (geofield_map) - Image Upload (deprecated)"),
description = "This Geofield Map Themer allows the definition of a unique
custom Marker Icon, valid for all the Map Markers.",
context = {"ViewStyle"},
weight = 0,
markerIconSelection = {
"type" = "managed_file",
"configSyncCompatibility" = FALSE,
},
defaultSettings = {
"values" = {},
"legend" = {
"class" = "custom-icon",
},
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\geofield_map\MapThemerBase implements ContainerFactoryPluginInterface, MapThemerInterface uses StringTranslationTrait
- class \Drupal\geofield_map\Plugin\GeofieldMapThemer\CustomIconThemer
- class \Drupal\geofield_map\MapThemerBase implements ContainerFactoryPluginInterface, MapThemerInterface uses StringTranslationTrait
Expanded class hierarchy of CustomIconThemer
File
- src/
Plugin/ GeofieldMapThemer/ CustomIconThemer.php, line 37
Namespace
Drupal\geofield_map\Plugin\GeofieldMapThemerView source
class CustomIconThemer extends MapThemerBase {
/**
* {@inheritdoc}
*/
public function buildMapThemerElement(array $defaults, array &$form, FormStateInterface $form_state, GeofieldGoogleMapViewStyle $geofieldMapView) {
// Get the existing (Default) Element settings.
$default_element = $this
->getDefaultThemerElement($defaults);
$file_upload_help = $this->markerIcon
->getFileUploadHelp();
$fid = (int) (!empty($default_element['icon_file']['fids'])) ? $default_element['icon_file']['fids'] : NULL;
$element = [
'#markup' => Markup::create($this
->t('<label>Custom Icon Image File</label>')),
'#type' => 'container',
'description' => [
'#markup' => Markup::create($this
->t('The chosen icon file will be used as Marker for all Geofield Map features @file_upload_help', [
'@file_upload_help' => $this->renderer
->renderPlain($file_upload_help),
])),
],
'icon_file' => $this->markerIcon
->getIconFileManagedElement($fid[0]),
'image_style' => [
'#type' => 'select',
'#title' => $this
->t('Image style'),
'#options' => $this->markerIcon
->getImageStyleOptions(),
'#default_value' => isset($default_element['image_style']) ? $default_element['image_style'] : 'geofield_map_default_icon_style',
'#states' => [
'visible' => [
':input[name="style_options[map_marker_and_infowindow][theming][geofieldmap_custom_icon][values][icon_file][is_svg]"]' => [
'checked' => FALSE,
],
],
],
],
'image_style_svg' => [
'#type' => 'container',
'warning' => [
'#markup' => $this
->t("Image style cannot apply to SVG Files,<br>SVG natural dimension will be applied."),
],
'#states' => [
'invisible' => [
':input[name="style_options[map_marker_and_infowindow][theming][geofieldmap_custom_icon][values][icon_file][is_svg]"]' => [
'checked' => FALSE,
],
],
],
],
'label_alias' => [
'#type' => 'textfield',
'#title' => $this
->t('Label alias'),
'#default_value' => isset($default_element['label_alias']) ? $default_element['label_alias'] : '',
'#description' => $this
->t('If not empty, this will be used in the legend.'),
'#size' => 20,
],
];
return $element;
}
/**
* {@inheritdoc}
*/
public function getIcon(array $datum, GeofieldGoogleMapViewStyle $geofieldMapView, EntityInterface $entity, $map_theming_values) {
// The Custom Icon Themer plugin defines a unique icon value.
if (!empty($map_theming_values['icon_file']['fids'])) {
$image_style = isset($map_theming_values['image_style']) ? $map_theming_values['image_style'] : 'none';
return $this->markerIcon
->getFileManagedUrl($map_theming_values['icon_file']['fids'][0], $image_style);
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function getLegend(array $map_theming_values, array $configuration = []) {
$legend = $this
->defaultLegendHeader($configuration);
// Get the icon image style, as result of the Legend configuration.
$image_style = isset($configuration['markers_image_style']) ? $configuration['markers_image_style'] : 'none';
// Get the map_theming_image_style, is so set.
if (isset($configuration['markers_image_style']) && $configuration['markers_image_style'] == '_map_theming_image_style_') {
$image_style = isset($map_theming_values['image_style']) ? $map_theming_values['image_style'] : 'none';
}
$fid = (int) (!empty($map_theming_values['icon_file']['fids'])) ? $map_theming_values['icon_file']['fids'][0] : NULL;
$legend['table']['custom-icon'] = [
'value' => [
'#type' => 'container',
'label' => [
'#markup' => !empty($map_theming_values['label_alias']) ? $map_theming_values['label_alias'] : $this
->t('All Markers'),
],
'#attributes' => [
'class' => [
'value',
],
],
],
'marker' => [
'#type' => 'container',
'icon_file' => !empty($fid) ? $this->markerIcon
->getLegendIconFromFid($fid, $image_style) : $this
->getDefaultLegendIcon(),
'#attributes' => [
'class' => [
'marker',
],
],
],
];
$legend['notes'] = [
'#markup' => isset($configuration['legend_notes']) ? $configuration['legend_notes'] : '',
'#attributes' => [
'class' => [
'notes',
],
],
];
return $legend;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CustomIconThemer:: |
public | function |
Provides a Map Themer Options Element. Overrides MapThemerInterface:: |
|
CustomIconThemer:: |
public | function |
Retrieve the icon for theming definition. Overrides MapThemerInterface:: |
|
CustomIconThemer:: |
public | function |
Generate the Legend render array. Overrides MapThemerInterface:: |
|
MapThemerBase:: |
protected | property | The config factory service. | 2 |
MapThemerBase:: |
protected | property | The Entity type manager service. | |
MapThemerBase:: |
protected | property | The Icon Managed File Service. | |
MapThemerBase:: |
protected | property | The Renderer service property. | |
MapThemerBase:: |
protected | property | The translation manager. | |
MapThemerBase:: |
protected | function | Builds the base table row for multivalue MapThemer. | |
MapThemerBase:: |
protected | function | Returns Default Table Header. | |
MapThemerBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
3 |
MapThemerBase:: |
protected | function | Returns the default Legend Footer. | |
MapThemerBase:: |
protected | function | Returns the default Legend Header. | |
MapThemerBase:: |
public | function |
Get the defaultSettings for the Map Themer Plugin. Overrides MapThemerInterface:: |
|
MapThemerBase:: |
protected | function | Returns the default Icon output for the Legend. | |
MapThemerBase:: |
public | function | ||
MapThemerBase:: |
public | function |
Get the MapThemer description property. Overrides MapThemerInterface:: |
|
MapThemerBase:: |
public | function | Generate Label Alias Help Message. | |
MapThemerBase:: |
protected | function | Gets the Map Themer Entity Bundles, based on the View Style Entity Type. | |
MapThemerBase:: |
public | function |
Get the MapThemer name property. Overrides MapThemerInterface:: |
|
MapThemerBase:: |
protected | function | Define if to return the default Legend Icon. | |
MapThemerBase:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
3 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |