From 3fdb6753e3f1b5fe05058be9f121069dd5851f24 Mon Sep 17 00:00:00 2001
From: Saurabh Vijayvargiya <saurabhvv0808@gmail.com>
Date: Mon, 31 Mar 2025 23:43:20 +0530
Subject: [PATCH 1/3] Issue #3507382: returning translated entity for the
 commented entity.

---
 core/modules/comment/src/Entity/Comment.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php
index a6fcb2e0f0ee..3a2d5a3d994a 100644
--- a/core/modules/comment/src/Entity/Comment.php
+++ b/core/modules/comment/src/Entity/Comment.php
@@ -363,7 +363,8 @@ public function getParentComment() {
    * {@inheritdoc}
    */
   public function getCommentedEntity() {
-    return $this->get('entity_id')->entity;
+    $language = $this->language()->getId();
+    return $this->get('entity_id')->entity->getTranslation($language);
   }
 
   /**
-- 
GitLab


From 0baf2f7dc42b5493c73697b2db6f70a85d1eea69 Mon Sep 17 00:00:00 2001
From: Saurabh Vijayvargiya <saurabhvv0808@gmail.com>
Date: Mon, 7 Apr 2025 12:53:24 +0530
Subject: [PATCH 2/3] Issue #3507382: Updated code for the failed test and
 added code to test for comment language.

---
 core/modules/comment/src/Entity/Comment.php   |  8 +++++++-
 .../src/Functional/CommentLanguageTest.php    | 20 +++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php
index 3a2d5a3d994a..d50727402bf3 100644
--- a/core/modules/comment/src/Entity/Comment.php
+++ b/core/modules/comment/src/Entity/Comment.php
@@ -11,6 +11,7 @@
 use Drupal\comment\CommentViewsData;
 use Drupal\comment\Form\DeleteForm;
 use Drupal\Core\Entity\Attribute\ContentEntityType;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityListBuilder;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
 use Drupal\Component\Utility\Number;
@@ -364,7 +365,12 @@ public function getParentComment() {
    */
   public function getCommentedEntity() {
     $language = $this->language()->getId();
-    return $this->get('entity_id')->entity->getTranslation($language);
+    /** @var EntityInterface $entity */
+    $entity = $this->get('entity_id')->entity;
+    if ($entity?->hasTranslation($language)) {
+      return $entity->getTranslation($language);
+    }
+    return $entity;
   }
 
   /**
diff --git a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
index 5da8ea42e10e..b89f47885fd0 100644
--- a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
@@ -162,6 +162,26 @@ public function testCommentLanguage(): void {
         $this->assertSession()->responseContains($value);
       }
     }
+
+    // Test clicking on comment titles and verifying pages load correctly.
+    $this->drupalGet('admin/content/comment');
+    
+    // Get all comment links on the page
+    $comment_links = $this->xpath('//td[contains(@class, "views-field-subject")]//a');
+    
+    foreach ($comment_links as $link) {
+      // Get the href attribute
+      $href = $link->getAttribute('href');
+      
+      // Click the link
+      $this->clickLink($link->getText());
+      
+      // Assert we're on a valid page (no 404 or other errors)
+      $this->assertSession()->statusCodeEquals(200);
+      
+      // Go back to the comment listing
+      $this->drupalGet('admin/content/comment');
+    }
   }
 
 }
-- 
GitLab


From d2773395c67561f683961258aaed80562b308fe4 Mon Sep 17 00:00:00 2001
From: Saurabh Vijayvargiya <saurabhvv0808@gmail.com>
Date: Mon, 7 Apr 2025 15:44:30 +0530
Subject: [PATCH 3/3] Issue #3507382: phpcs fixes.

---
 core/modules/comment/src/Entity/Comment.php         |  3 +--
 .../tests/src/Functional/CommentLanguageTest.php    | 13 +------------
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php
index d50727402bf3..77d687f2fa8e 100644
--- a/core/modules/comment/src/Entity/Comment.php
+++ b/core/modules/comment/src/Entity/Comment.php
@@ -11,7 +11,6 @@
 use Drupal\comment\CommentViewsData;
 use Drupal\comment\Form\DeleteForm;
 use Drupal\Core\Entity\Attribute\ContentEntityType;
-use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityListBuilder;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
 use Drupal\Component\Utility\Number;
@@ -365,7 +364,7 @@ public function getParentComment() {
    */
   public function getCommentedEntity() {
     $language = $this->language()->getId();
-    /** @var EntityInterface $entity */
+    /** @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $this->get('entity_id')->entity;
     if ($entity?->hasTranslation($language)) {
       return $entity->getTranslation($language);
diff --git a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
index b89f47885fd0..2776458fdf23 100644
--- a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php
@@ -163,23 +163,12 @@ public function testCommentLanguage(): void {
       }
     }
 
-    // Test clicking on comment titles and verifying pages load correctly.
     $this->drupalGet('admin/content/comment');
-    
-    // Get all comment links on the page
     $comment_links = $this->xpath('//td[contains(@class, "views-field-subject")]//a');
-    
+
     foreach ($comment_links as $link) {
-      // Get the href attribute
-      $href = $link->getAttribute('href');
-      
-      // Click the link
       $this->clickLink($link->getText());
-      
-      // Assert we're on a valid page (no 404 or other errors)
       $this->assertSession()->statusCodeEquals(200);
-      
-      // Go back to the comment listing
       $this->drupalGet('admin/content/comment');
     }
   }
-- 
GitLab