You are here

public function EntityTypeThemer::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 EntityTypeThemerUrl::getLegend

File

src/Plugin/GeofieldMapThemer/EntityTypeThemer.php, line 148

Class

EntityTypeThemer
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);
  foreach ($map_theming_values as $bundle => $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[$bundle]['image_style']) ? $map_theming_values[$bundle]['image_style'] : 'none';
    }
    $fid = (int) (!empty($value['icon_file']['fids'])) ? $value['icon_file']['fids'] : 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($fid) && !$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($fid) ? $this->markerIcon
          ->getLegendIconFromFid($fid, $image_style) : $this
          ->getDefaultLegendIcon(),
        '#attributes' => [
          'class' => [
            'marker',
          ],
        ],
      ],
    ];
  }
  $legend['notes'] = $this
    ->defaultLegendFooter($configuration);
  return $legend;
}