You are here

public function TaxonomyTermThemerUrl::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 MapThemerInterface::getLegend

1 method overrides TaxonomyTermThemerUrl::getLegend()
TaxonomyTermThemer::getLegend in src/Plugin/GeofieldMapThemer/TaxonomyTermThemer.php
Generate the Legend render array.

File

src/Plugin/GeofieldMapThemer/TaxonomyTermThemerUrl.php, line 340

Class

TaxonomyTermThemerUrl
Style plugin to render a View output as a Leaflet map.

Namespace

Drupal\geofield_map\Plugin\GeofieldMapThemer

Code

public function getLegend(array $map_theming_values, array $configuration = []) {
  $legend = $this
    ->defaultLegendHeader($configuration);

  // Get the icon image width, as result of the Legend configuration.
  $icon_width = isset($configuration['markers_width']) ? $configuration['markers_width'] : 50;
  $taxonomy_field = $map_theming_values['taxonomy_field'];
  foreach ($map_theming_values['fields'][$taxonomy_field]['terms'] as $vid => $term) {
    $icon_file_uri = !empty($term['icon_file']) ? $term['icon_file'] : 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($term['legend_exclude']) || $icon_file_uri == 'none' && !$this
      ->renderDefaultLegendIcon()) {
      continue;
    }
    $label = isset($term['label']) ? $term['label'] : $vid;
    $legend['table'][$vid] = [
      'value' => [
        '#type' => 'container',
        'label' => [
          '#markup' => !empty($term['label_alias']) ? $term['label_alias'] : $label,
        ],
        '#attributes' => [
          'class' => [
            'value',
          ],
        ],
      ],
      'marker' => [
        '#type' => 'container',
        'icon_file' => !empty($icon_file_uri) && $icon_file_uri != 'none' ? $this->markerIcon
          ->getLegendIconFromFileUri($icon_file_uri, $icon_width) : $this
          ->getDefaultLegendIcon(),
        '#attributes' => [
          'class' => [
            'marker',
          ],
        ],
      ],
    ];
  }
  $legend['notes'] = $this
    ->defaultLegendFooter($configuration);
  return $legend;
}