converted geofields to paragarphs, updated SiteMap.php

This commit is contained in:
2025-01-27 13:11:17 +01:00
parent be90064f2a
commit d912155cd0
18 changed files with 437 additions and 255 deletions

View File

@@ -7,6 +7,7 @@ use Drupal\Core\Block\Attribute\Block;
// use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Link;
use Drupal\Core\Render\Markup;
use Drupal\paragraphs\Entity\Paragraph;
/**
* Provides a 'Sites Map' Block.
@@ -32,25 +33,46 @@ class SitesMap extends BlockBase {
$sites_paths = "";
foreach($allSites as $index => $site){
$title = $site->get('title')->getString();
$subtitle = $site->get('field_sous_titre')->getString();
$place = $site->get('field_localisation_textuel')->getString();
// Check if the node has the paragraph field and it's not empty.
if ($site->hasField('field_carte') && !$site->get('field_carte')->isEmpty()) {
// Iterate through the referenced paragraph entities.
foreach ($site->get('field_carte')->referencedEntities() as $carte_paragraph) {
if ($carte_paragraph instanceof Paragraph) {
$geofield = $carte_paragraph->get('field_carte');
$principal = $carte_paragraph->get('field_principal')->value;
$link_options = ['absolute' => FALSE, 'attributes' => ['class' => 'site-link']];
$site_link_object = Link::createFromRoute("voir le site", 'entity.node.canonical', ['node' => $site->id()], $link_options);
$href = $site_link_object->getUrl()->toString();
if ($geofield && $principal) {
$geofield = $site->get('field_carte')->get(0);
$lon = $geofield->lon;
$lat = $geofield->lat;
$title = $site->get('title')->getString();
$subtitle = $site->get('field_sous_titre')->getString();
$place = $site->get('field_localisation_textuel')->getString();
$link_options = ['absolute' => FALSE, 'attributes' => ['class' => 'site-link']];
$site_link_object = Link::createFromRoute("voir le site", 'entity.node.canonical', ['node' => $site->id()], $link_options);
$href = $site_link_object->getUrl()->toString();
$lon = $geofield->lon;
$lat = $geofield->lat;
$svg_template_path = DRUPAL_ROOT . '/modules/custom/erable_mod/assets/svg/feuille.svg';
$svg_template= file_get_contents($svg_template_path);
$sites_paths .= str_replace(
['$index', '$lon', '$lat', '$href', '$title', '$place'],
[$index, $lon, $lat, $href, $title, $place],
$svg_template
);
$svg_template_path = DRUPAL_ROOT . '/modules/custom/erable_mod/assets/svg/feuille.svg';
$svg_template= file_get_contents($svg_template_path);
$sites_paths .= str_replace(
['$index', '$lon', '$lat', '$href', '$title', '$place'],
[$index, $lon, $lat, $href, $title, $place],
$svg_template
);
break;
}
}
}
}
}
$return = [