map translation

This commit is contained in:
Bachir Soussi Chiadmi 2024-11-14 12:14:14 +01:00
parent d740d58c0b
commit 788f00a603
1 changed files with 7 additions and 3 deletions

View File

@ -21,6 +21,8 @@ class SitesMap extends BlockBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function build() { public function build() {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$return = null; $return = null;
$allSites = \Drupal::entityTypeManager()->getStorage('node') $allSites = \Drupal::entityTypeManager()->getStorage('node')
@ -39,12 +41,14 @@ class SitesMap extends BlockBase {
foreach($allSites as $index => $site){ foreach($allSites as $index => $site){
$title = $site->get('title')->getString(); // $title = $site->get('title')->getString();
$subtitle = $site->get('field_sous_titre')->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']]; // 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("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(); $link = $site_link_object->toString()->getGeneratedLink();
$datacontent = htmlspecialchars("<strong>$title</strong><br>$subtitle<br>$link"); $datacontent = htmlspecialchars("<strong>$title</strong><br>$subtitle<br>$link");