custom map language aware links url; patched core for image field link language aware

This commit is contained in:
Bachir Soussi Chiadmi 2024-12-02 11:03:07 +01:00
parent bfb94ef05b
commit 5a48eee4ef
2 changed files with 6 additions and 1 deletions

View File

@ -126,6 +126,9 @@
"merge-extra": true "merge-extra": true
}, },
"patches": { "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":{ "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" "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"
}, },

View File

@ -41,12 +41,14 @@ class SitesMap extends BlockBase {
foreach($allSites as $index => $site){ foreach($allSites as $index => $site){
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
// $title = $site->get('title')->getString(); // $title = $site->get('title')->getString();
$title = $site->hasTranslation($language) ? $site->getTranslation($language)->get('title')->getString() : $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->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();
$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_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); $site_link_object = Link::createFromRoute(t("got to site"), 'entity.node.canonical', ['node' => $site->id()], $link_options);
$link = $site_link_object->toString()->getGeneratedLink(); $link = $site_link_object->toString()->getGeneratedLink();