diff --git a/config/sync/field.field.node.static.field_map_block.yml b/config/sync/field.field.node.static.field_map_block.yml index 5b47170..bdb07aa 100644 --- a/config/sync/field.field.node.static.field_map_block.yml +++ b/config/sync/field.field.node.static.field_map_block.yml @@ -21,5 +21,6 @@ settings: selection: blocks selection_settings: plugin_ids: + projetsmap_block: projetsmap_block sitesmap_block: sitesmap_block field_type: block_field diff --git a/config/sync/pathauto.pattern.projets.yml b/config/sync/pathauto.pattern.projets.yml new file mode 100644 index 0000000..a7bf1a9 --- /dev/null +++ b/config/sync/pathauto.pattern.projets.yml @@ -0,0 +1,22 @@ +uuid: 658b6e7b-ca66-4393-a395-48ceecd74eba +langcode: fr +status: true +dependencies: + module: + - node +id: projets +label: Projets +type: 'canonical_entities:node' +pattern: '/projets/[node:title]' +selection_criteria: + e4b92eaa-98ed-445e-af7f-d5f8f5f1ce4a: + id: 'entity_bundle:node' + negate: false + uuid: e4b92eaa-98ed-445e-af7f-d5f8f5f1ce4a + context_mapping: + node: node + bundles: + projet: projet +selection_logic: and +weight: -5 +relationships: { } diff --git a/web/modules/custom/q2d_mod/q2d_mod.libraries.yml b/web/modules/custom/q2d_mod/q2d_mod.libraries.yml index 674b807..90322cd 100644 --- a/web/modules/custom/q2d_mod/q2d_mod.libraries.yml +++ b/web/modules/custom/q2d_mod/q2d_mod.libraries.yml @@ -1,4 +1,11 @@ sites_map_block: + css: + theme: + assets/css/fontface.css: {} + assets/css/carte-interactive-qdd.css: {} + js: + assets/js/carte-interactive-qdd.js: {} +projets_map_block: css: theme: assets/css/fontface.css: {} diff --git a/web/modules/custom/q2d_mod/q2d_mod.module b/web/modules/custom/q2d_mod/q2d_mod.module index c535d39..c92de71 100644 --- a/web/modules/custom/q2d_mod/q2d_mod.module +++ b/web/modules/custom/q2d_mod/q2d_mod.module @@ -13,5 +13,8 @@ function q2d_mod_theme() { 'svg_mapsites' => array( 'variables' => array('vpw' => null, 'vph' => null, 'sites' => [], 'label' => null), ), + 'svg_mapprojets' => 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/ProjetsMap.php b/web/modules/custom/q2d_mod/src/Plugin/Block/ProjetsMap.php new file mode 100644 index 0000000..809a65d --- /dev/null +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/ProjetsMap.php @@ -0,0 +1,156 @@ +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(); + + // $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' => 'site-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($title, 'entity.node.canonical', ['node' => $site->id()], $link_options); + $link = $site_link_object->toString()->getGeneratedLink(); + + $projets = \Drupal::entityTypeManager()->getStorage('node') + ->loadByProperties([ + 'type' => 'projet', + 'status' => 1, + 'field_site_projet' => $site->id() + ]); + + + + $datahtml = "$link
$subtitle"; + + $datacontent = htmlspecialchars($datahtml); + + + + $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_mapprojets', + '#label' => "Les 30 projets", + '#sites' => $sites_paths, + '#vpw' => $vp_w, + '#vph' => $vp_h, + '#attached' => [ + 'library' => [ + 'q2d_mod/projets_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-mapprojets.html.twig b/web/modules/custom/q2d_mod/templates/svg-mapprojets.html.twig new file mode 100644 index 0000000..66528e9 --- /dev/null +++ b/web/modules/custom/q2d_mod/templates/svg-mapprojets.html.twig @@ -0,0 +1,55 @@ +
+ +

{{label}}

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