public function ListFieldThemer::getLegend in Geofield Map 8.2
Generate the Legend render array.
Parameters
array $map_theming_values: The Map themer mapping values.
array $configuration: The legend block configuration array.
Return value
mixed The icon definition.
Overrides ListFieldThemerUrl::getLegend
File
- src/
Plugin/ GeofieldMapThemer/ ListFieldThemer.php, line 238
Class
- ListFieldThemer
- Style plugin to render a View output as a Leaflet map.
Namespace
Drupal\geofield_map\Plugin\GeofieldMapThemerCode
public function getLegend(array $map_theming_values, array $configuration = []) {
$legend = $this
->defaultLegendHeader($configuration);
$list_field = $map_theming_values['list_field'];
foreach ($map_theming_values['fields'][$list_field]['options'] as $key => $value) {
// 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['fields'][$list_field]['options'][$key]['image_style']) ? $map_theming_values['fields'][$list_field]['options'][$key]['image_style'] : 'none';
}
$fid = (int) (!empty($value['icon_file']['fids'])) ? $value['icon_file']['fids'] : NULL;
// Don't render legend row in case:
// - the specific value is flagged as excluded from the Legend, or
// - no image is associated and the plugin denies to render the
// DefaultLegendIcon definition.
if (!empty($value['legend_exclude']) || empty($fid) && !$this
->renderDefaultLegendIcon()) {
continue;
}
$label = isset($value['label']) ? $value['label'] : $key;
$legend['table'][$key] = [
'value' => [
'#type' => 'container',
'label' => [
'#markup' => !empty($value['label_alias']) ? $value['label_alias'] : $label,
],
'#attributes' => [
'class' => [
'value',
],
],
],
'marker' => [
'#type' => 'container',
'icon_file' => !empty($fid) ? $this->markerIcon
->getLegendIconFromFid($fid, $image_style) : $this
->getDefaultLegendIcon(),
'#attributes' => [
'class' => [
'marker',
],
],
],
];
}
$legend['notes'] = $this
->defaultLegendFooter($configuration);
return $legend;
}