From ba4116a084fd33f3da68d043032eda07a0a1e4cb Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 12 Nov 2025 10:45:21 +0100 Subject: [PATCH] galerie photo map + link --- ...age_variant.node_view-panels_variant-3.yml | 14 ++ web/modules/custom/q2d_mod/q2d_mod.module | 3 + .../src/Plugin/Block/GaleriePhotoMap.php | 139 ++++++++++++++++++ .../templates/svg-mapgaleries.html.twig | 55 +++++++ 4 files changed, 211 insertions(+) create mode 100644 web/modules/custom/q2d_mod/src/Plugin/Block/GaleriePhotoMap.php create mode 100644 web/modules/custom/q2d_mod/templates/svg-mapgaleries.html.twig diff --git a/config/sync/page_manager.page_variant.node_view-panels_variant-3.yml b/config/sync/page_manager.page_variant.node_view-panels_variant-3.yml index 18d2c4d..b085efa 100644 --- a/config/sync/page_manager.page_variant.node_view-panels_variant-3.yml +++ b/config/sync/page_manager.page_variant.node_view-panels_variant-3.yml @@ -8,6 +8,7 @@ dependencies: - ctools_block - node - panels + - q2d_mod id: node_view-panels_variant-3 label: 'Galeries Photo' weight: 0 @@ -193,6 +194,19 @@ variant_settings: - '' html_id: '' css_styles: '' + 1d37c481-092d-460a-ac84-3283c44147ae: + id: galeriephotomap_block + label: 'Galerie Photo map Block' + label_display: '0' + provider: q2d_mod + context_mapping: { } + region: first + weight: 0 + uuid: 1d37c481-092d-460a-ac84-3283c44147ae + css_classes: + - '' + html_id: '' + css_styles: '' page_title: '' layout: layout_threecol_25_50_25 layout_settings: diff --git a/web/modules/custom/q2d_mod/q2d_mod.module b/web/modules/custom/q2d_mod/q2d_mod.module index c92de71..b6e66b3 100644 --- a/web/modules/custom/q2d_mod/q2d_mod.module +++ b/web/modules/custom/q2d_mod/q2d_mod.module @@ -16,5 +16,8 @@ function q2d_mod_theme() { 'svg_mapprojets' => array( 'variables' => array('vpw' => null, 'vph' => null, 'sites' => [], 'label' => null), ), + 'svg_mapgaleries' => array( + 'variables' => array('vpw' => null, 'vph' => null, 'sites' => [], 'label' => null), + ), ); } \ No newline at end of file diff --git a/web/modules/custom/q2d_mod/src/Plugin/Block/GaleriePhotoMap.php b/web/modules/custom/q2d_mod/src/Plugin/Block/GaleriePhotoMap.php new file mode 100644 index 0000000..e6e3ae1 --- /dev/null +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/GaleriePhotoMap.php @@ -0,0 +1,139 @@ +getCurrentLanguage()->getId(); + + $return = null; + + $allSites = \Drupal::entityTypeManager()->getStorage('node') + ->loadByProperties(['type' => 'site', 'status' => 1]); + + $sites_paths = ""; + + $vp_w = 600; + $vp_h = 600; + + // Coordonnées géographiques des coins de la carte (France) + $latTop = 52.0; // Nord-Ouest (coin supérieur gauche) + $lonLeft = -6.0; + $latBottom = 40.0; // Sud-Est (coin inférieur droit) + $lonRight = 11.0; + + + foreach($allSites as $index => $site){ + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + + + // /ressources?field_type_de_ressource_target_id[]=17&combine=&field_tous_les_sites_value=All&field_site_target_id_verf[]=37 + $query = [ + 'field_type_de_ressource_target_id[]' => 17, # fixed to galeries_photos + 'combine' => '', + 'field_tous_les_sites_value' => 'All', + 'field_site_target_id_verf[]' => $site->id(), + ]; + $url = Url::fromRoute('view.ressources.page_1', [], ['query' => $query])->toString(); + + + // $title = $site->get('title')->getString(); + $title = $site->hasTranslation($language) ? $site->getTranslation($language)->get('title')->getString() : $site->get('title')->getString(); + // $subtitle = $site->get('field_sous_titre')->getString(); + $subtitle = $site->hasTranslation($language) ? $site->getTranslation($language)->get('field_sous_titre')->getString() : $site->get('field_sous_titre')->getString(); + + $link_options = ['absolute' => TRUE, 'attributes' => ['class' => 'ressource-link'], 'language' => \Drupal::languageManager()->getLanguage($langcode)]; // Passer 'absolute' à TRUE + // $site_url = $site->toUrl('canonical', $link_options)->toString(); // URL absolue pour le data-url + $site_link_object = Link::createFromRoute(t("Voir le site"), 'entity.node.canonical', ['node' => $site->id()], $link_options); + $link = $site_link_object->toString()->getGeneratedLink(); + + $datacontent = htmlspecialchars("$title
$subtitle
$link"); + + $geofield = $site->get('field_geofield')->get(0); + $lon = $geofield->lon; + $lat = $geofield->lat; + $geofieldData = "$lon,$lat"; // Utiliser une chaîne pour stocker la position + + $x = round(($lon - $lonLeft) / ($lonRight - $lonLeft) * $vp_w); + $y = round(($latTop - $lat) / ($latTop - $latBottom) * $vp_h); + + $r = 12; + $m = -$r/1.5+3; + $l = $r/1.5 +2.5; + $sites_paths .= << + > + + + + + + + + + + SVGSITEPATH; + } + + + $return = [ + '#cache' => [ + 'max-age' => 0, + ], + 'svg_mapsites' => [ + '#theme' => 'svg_mapgaleries', + '#label' => "Voir les autres galeries photos", + '#sites' => $sites_paths, + '#vpw' => $vp_w, + '#vph' => $vp_h, + '#attached' => [ + 'library' => [ + 'q2d_mod/sites_map_block', + ], + ], + ] + ]; + + return $return; + // return [ + // '#markup' => $this->t('Hello, Sites Map!'), + // ]; + } + + public function getCacheMaxAge() { + return 0; + } +} \ No newline at end of file diff --git a/web/modules/custom/q2d_mod/templates/svg-mapgaleries.html.twig b/web/modules/custom/q2d_mod/templates/svg-mapgaleries.html.twig new file mode 100644 index 0000000..66528e9 --- /dev/null +++ b/web/modules/custom/q2d_mod/templates/svg-mapgaleries.html.twig @@ -0,0 +1,55 @@ +
+ +

{{label}}

+ + {# + + #} + + + + + + + + + + {{ sites|raw }} + + + + + + + + +
\ No newline at end of file