From 5a48eee4effc888d48fbf97abaac62cfa9513b2f Mon Sep 17 00:00:00 2001 From: bach Date: Mon, 2 Dec 2024 11:03:07 +0100 Subject: [PATCH] custom map language aware links url; patched core for image field link language aware --- composer.json | 3 +++ web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 724484b..44b36a6 100644 --- a/composer.json +++ b/composer.json @@ -126,6 +126,9 @@ "merge-extra": true }, "patches": { + "drupal/core": { + "Image field generates only default language URL when linking to corresponding entity. https://www.drupal.org/node/2645922?no_cache=1733132298":"https://www.drupal.org/files/issues/2021-03-15/2645922-45.patch" + }, "drupal/social_media_links":{ "Replace Twitter with X https://www.drupal.org/project/social_media_links/issues/3384469": "https://www.drupal.org/files/issues/2023-09-12/social_media_links-change_twitter_to_x-3384469-7.patch" }, 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 7219ec2..b54f57b 100644 --- a/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php +++ b/web/modules/custom/q2d_mod/src/Plugin/Block/SitesMap.php @@ -41,12 +41,14 @@ class SitesMap extends BlockBase { 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']]; // Passer 'absolute' à TRUE + $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(t("got to site"), 'entity.node.canonical', ['node' => $site->id()], $link_options); $link = $site_link_object->toString()->getGeneratedLink();