From 98217b5bbe5ee1a40cd9abfb177f33aa894fabd6 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 4 May 2023 09:34:31 +0100
Subject: [PATCH] Issue #2986372 by ranjith_kumar_k_u, robertom, _utsavsharma,
 smustgrave, penyaskito, catch, larowlan: "Comments per page" setting cannot
 be configured to "all comments"

---
 .../src/Plugin/Field/FieldType/CommentItem.php       |  3 ++-
 .../tests/src/Functional/CommentFieldsTest.php       |  9 +++++++++
 .../tests/src/Functional/CommentPagerTest.php        | 12 ++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php
index b3934b9d9c7e..8833651a3dca 100644
--- a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php
+++ b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php
@@ -118,8 +118,9 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
       '#title' => $this->t('Comments per page'),
       '#default_value' => $settings['per_page'],
       '#required' => TRUE,
-      '#min' => 1,
+      '#min' => 0,
       '#max' => 1000,
+      '#description' => $this->t('Enter 0 to show all comments.'),
     ];
     $element['anonymous'] = [
       '#type' => 'select',
diff --git a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
index 23565102837b..ae1038cb21b0 100644
--- a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
@@ -184,6 +184,15 @@ public function testCommentFieldCreate() {
     $this->submitForm($edit, 'Save field settings');
     // We shouldn't get an error message.
     $this->assertSession()->pageTextNotContains('The submitted value in the Comment type element is not allowed.');
+
+    // Try to save the comment field with "Comments per page"
+    // setting value as zero.
+    $edit = [
+      'settings[per_page]' => 0,
+    ];
+    $this->drupalGet('admin/config/people/accounts/fields/user.user.field_user_comment');
+    $this->submitForm($edit, 'Save settings');
+    $this->assertSession()->statusMessageContains('Saved User comment configuration.', 'status');
   }
 
   /**
diff --git a/core/modules/comment/tests/src/Functional/CommentPagerTest.php b/core/modules/comment/tests/src/Functional/CommentPagerTest.php
index 4039e2b36d55..2f25713e0ea5 100644
--- a/core/modules/comment/tests/src/Functional/CommentPagerTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentPagerTest.php
@@ -38,6 +38,14 @@ public function testCommentPaging() {
 
     $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
 
+    // Set "Comments per page" as zero and verify that all comments are appearing
+    // on the page.
+    $this->setCommentsPerPage(0);
+    $this->drupalGet('node/' . $node->id());
+    $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page.');
+    $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page.');
+    $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page.');
+
     // Set comments to one per page so that we are able to test paging without
     // needing to insert large numbers of comments.
     $this->setCommentsPerPage(1);
@@ -92,6 +100,10 @@ public function testCommentPaging() {
     $this->setCommentsPerPage(0);
     $this->drupalGet('node/' . $node->id(), ['query' => ['page' => 0]]);
     $this->assertFalse($this->commentExists($reply2, TRUE), 'Threaded mode works correctly when comments per page is 0.');
+    // Test that all main comments are appearing in the threaded mode.
+    $this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page.');
+    $this->assertTrue($this->commentExists($comments[1]), 'Comment 2 appears on page.');
+    $this->assertTrue($this->commentExists($comments[2]), 'Comment 3 appears on page.');
 
     $this->drupalLogout();
   }
-- 
GitLab