From 788f00a603d0698aa43d3fe268d4f44aa00899bf Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 14 Nov 2024 12:14:14 +0100 Subject: [PATCH] map translation --- .../custom/q2d_mod/src/Plugin/Block/SitesMap.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php b/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php index fcd1444..18ef0be 100644 --- a/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php @@ -21,6 +21,8 @@ class SitesMap extends BlockBase { * {@inheritdoc} */ public function build() { + $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); + $return = null; $allSites = \Drupal::entityTypeManager()->getStorage('node') @@ -39,12 +41,14 @@ class SitesMap extends BlockBase { foreach($allSites as $index => $site){ - $title = $site->get('title')->getString(); - $subtitle = $site->get('field_sous_titre')->getString(); + // $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']]; // Passer 'absolute' à TRUE $site_url = $site->toUrl('canonical', $link_options)->toString(); // URL absolue pour le data-url - $site_link_object = Link::createFromRoute("voir le site", 'entity.node.canonical', ['node' => $site->id()], $link_options); + $site_link_object = Link::createFromRoute(t("got to site"), 'entity.node.canonical', ['node' => $site->id()], $link_options); $link = $site_link_object->toString()->getGeneratedLink(); $datacontent = htmlspecialchars("$title
$subtitle
$link");