carte ressources va directement sur mission photo
This commit is contained in:
@@ -163,25 +163,58 @@ svgElement.addEventListener('mouseout', function(event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Gérer les clics pour la page node-type-site uniquement
|
|
||||||
svgElement.addEventListener('click', function(event) {
|
// Gérer les clics sur les cercles de la carte
|
||||||
|
if (svgElement) {
|
||||||
|
svgElement.addEventListener('click', function(event) {
|
||||||
|
const target = event.target;
|
||||||
|
|
||||||
|
if (!target.classList || !target.classList.contains('site-link')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On récupère les URLs
|
||||||
|
const missionUrl = target.getAttribute('data-mission-photo-url');
|
||||||
|
const fallbackUrl = target.getAttribute('data-url');
|
||||||
|
|
||||||
|
// 1) Page RESSOURCE : priorité à la mission photo
|
||||||
|
if (isNodeTypeRessourcePage) {
|
||||||
|
event.preventDefault(); // empêche le <a href="..."> d'agir
|
||||||
|
|
||||||
|
if (missionUrl) {
|
||||||
|
window.location.href = missionUrl; // Aller directement à la mission photo
|
||||||
|
} else if (fallbackUrl) {
|
||||||
|
window.location.href = fallbackUrl; // Sinon, on garde le comportement actuel
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Page SITE : comportement actuel
|
||||||
if (isNodeTypeSitePage) {
|
if (isNodeTypeSitePage) {
|
||||||
if (event.target.classList.contains('site-link')) {
|
if (fallbackUrl) {
|
||||||
const targetUrl = event.target.getAttribute('data-url');
|
event.preventDefault();
|
||||||
if (targetUrl) {
|
window.location.href = fallbackUrl;
|
||||||
window.location.href = targetUrl; // Redirige vers le data-url correspondant
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3) Page PROJET : comportement actuel
|
||||||
if (isNodeTypeProjetPage) {
|
if (isNodeTypeProjetPage) {
|
||||||
if (event.target.classList.contains('site-link')) {
|
if (fallbackUrl) {
|
||||||
const targetUrl = event.target.getAttribute('data-url');
|
event.preventDefault();
|
||||||
if (targetUrl) {
|
window.location.href = fallbackUrl;
|
||||||
window.location.href = targetUrl; // Redirige vers le data-url correspondant
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4) Autres pages : si tu veux un comportement par défaut
|
||||||
|
// if (fallbackUrl) {
|
||||||
|
// event.preventDefault();
|
||||||
|
// window.location.href = fallbackUrl;
|
||||||
|
// }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Fonction pour gérer l'agrandissement de views-row au survol des cercles
|
// Fonction pour gérer l'agrandissement de views-row au survol des cercles
|
||||||
if (isLessitesPage) {
|
if (isLessitesPage) {
|
||||||
|
|||||||
@@ -34,6 +34,34 @@ class GaleriePhotoMap extends BlockBase {
|
|||||||
$vp_w = 600;
|
$vp_w = 600;
|
||||||
$vp_h = 600;
|
$vp_h = 600;
|
||||||
|
|
||||||
|
// Charger toutes les ressources de type "Mission photo" (type de ressource = 17)
|
||||||
|
$all_mission_photos = \Drupal::entityTypeManager()
|
||||||
|
->getStorage('node')
|
||||||
|
->loadByProperties([
|
||||||
|
'type' => 'ressource', // adapte si ton type machine est différent
|
||||||
|
'status' => 1,
|
||||||
|
'field_type_de_ressource' => 17, // même ID que dans la query de la vue
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Indexer les missions photo par ID de site
|
||||||
|
$mission_by_site = [];
|
||||||
|
|
||||||
|
foreach ($all_mission_photos as $mission) {
|
||||||
|
if (!$mission->hasField('field_site') || $mission->get('field_site')->isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un même node peut être lié à plusieurs sites : on en prend un par site
|
||||||
|
foreach ($mission->get('field_site') as $ref) {
|
||||||
|
$site_id = $ref->target_id;
|
||||||
|
|
||||||
|
if (!isset($mission_by_site[$site_id])) {
|
||||||
|
$mission_by_site[$site_id] = $mission;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Coordonnées géographiques des coins de la carte (France)
|
// Coordonnées géographiques des coins de la carte (France)
|
||||||
$latTop = 52.0; // Nord-Ouest (coin supérieur gauche)
|
$latTop = 52.0; // Nord-Ouest (coin supérieur gauche)
|
||||||
$lonLeft = -6.0;
|
$lonLeft = -6.0;
|
||||||
@@ -60,6 +88,24 @@ class GaleriePhotoMap extends BlockBase {
|
|||||||
// $subtitle = $site->get('field_sous_titre')->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();
|
$subtitle = $site->hasTranslation($language) ? $site->getTranslation($language)->get('field_sous_titre')->getString() : $site->get('field_sous_titre')->getString();
|
||||||
|
|
||||||
|
// URL directe de la mission photo liée à ce site (si trouvée)
|
||||||
|
$mission_photo_url = '';
|
||||||
|
|
||||||
|
if (isset($mission_by_site[$site->id()])) {
|
||||||
|
$mission_node = $mission_by_site[$site->id()];
|
||||||
|
|
||||||
|
// Respecter la langue courante si traduction existe
|
||||||
|
if ($mission_node->hasTranslation($language)) {
|
||||||
|
$mission_node = $mission_node->getTranslation($language);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mission_photo_url = $mission_node->toUrl('canonical', [
|
||||||
|
'absolute' => TRUE,
|
||||||
|
'language' => \Drupal::languageManager()->getLanguage($langcode),
|
||||||
|
])->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$link_options = ['absolute' => TRUE, 'attributes' => ['class' => 'ressource-link'], 'language' => \Drupal::languageManager()->getLanguage($langcode)]; // Passer 'absolute' à TRUE
|
$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_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);
|
$site_link_object = Link::createFromRoute(t("Voir le site"), 'entity.node.canonical', ['node' => $site->id()], $link_options);
|
||||||
@@ -93,6 +139,7 @@ class GaleriePhotoMap extends BlockBase {
|
|||||||
class="site-link"
|
class="site-link"
|
||||||
data-content="$datacontent"
|
data-content="$datacontent"
|
||||||
data-url="$url"
|
data-url="$url"
|
||||||
|
data-mission-photo-url="$mission_photo_url"
|
||||||
cx="0" cy="0" r="$r"
|
cx="0" cy="0" r="$r"
|
||||||
style="fill-opacity:1;fill-rule:nonzero;" />
|
style="fill-opacity:1;fill-rule:nonzero;" />
|
||||||
<path
|
<path
|
||||||
|
|||||||
Reference in New Issue
Block a user