You are here

public function EntityTypeThemerUrl::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 EntityTypeThemerUrl::getLegend()
EntityTypeThemer::getLegend in src/Plugin/GeofieldMapThemer/EntityTypeThemer.php
Generate the Legend render array.

File

src/Plugin/GeofieldMapThemer/EntityTypeThemerUrl.php, line 206

Class

EntityTypeThemerUrl
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;
  foreach ($map_theming_values as $bundle => $value) {
    $icon_file_uri = !empty($value['icon_file']) && $value['icon_file'] != 'none' ? $value['icon_file'] : NULL;

    // Don't render legend row in case no image is associated and the plugin
    // denies to render the DefaultLegendIcon definition.
    if (!empty($value['legend_exclude']) || empty($icon_file_uri) && !$this
      ->renderDefaultLegendIcon()) {
      continue;
    }
    $label = isset($value['label']) ? $value['label'] : $bundle;
    $legend['table'][$bundle] = [
      'value' => [
        '#type' => 'container',
        'label' => [
          '#markup' => !empty($value['label_alias']) ? $value['label_alias'] : $label,
        ],
        '#attributes' => [
          'class' => [
            'value',
          ],
        ],
      ],
      'marker' => [
        '#type' => 'container',
        'icon_file' => !empty($icon_file_uri) ? $this->markerIcon
          ->getLegendIconFromFileUri($icon_file_uri, $icon_width) : $this
          ->getDefaultLegendIcon(),
        '#attributes' => [
          'class' => [
            'marker',
          ],
        ],
      ],
    ];
  }
  $legend['notes'] = $this
    ->defaultLegendFooter($configuration);
  return $legend;
}