How to add attributes to Google Static Maps?

Created on 21 November 2023, about 1 year ago
Updated 4 February 2024, 10 months ago

Problem/Motivation

I want to add attributes like class or loading="lazy" to the static image of the submodule geolocation_google_static_maps.

I used the following preprocess-function, but that didn't work:

function THEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'field_geolocation') {
    $variables['items'][0]['content']['#attributes']['loading'] = 'lazy';
  }
}

How can i add attributes to the content of the field?

💬 Support request
Status

Closed: works as designed

Version

3.12

Component

Geolocation Field / Backend

Created by

🇩🇪Germany tfranz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @tfranz
  • Status changed to Postponed: needs info 12 months ago
  • 🇩🇪Germany christianadamski Berlin, Germany

    The relevant code is:

     return [
          '#theme' => 'image',
          '#uri' => $this->signUrl($static_map_url),
          '#google_static_map' => [
            'map_settings' => $map_settings,
            'context' => $context,
          ],
        ];
    

    geolocation/modules/geolocation_google_maps/modules/geolocation_google_static_maps/src/Plugin/geolocation/MapProvider/GoogleStaticMaps.php:176

    So you would want to preprocess the image I assume.

  • Status changed to Closed: works as designed 10 months ago
  • 🇩🇪Germany christianadamski Berlin, Germany
Production build 0.71.5 2024