Problem/Motivation

When no subject is set explicitly for a comment, it is automatically derived by truncating the comment body. This often leads to fragmented sentence parts being the comment subjects, which can look strange and out of place.

Proposed resolution

Add an ellipsis character to the end of the trimmed comment subject.
A screenshot of three comments on a Drupal site in the Bartik theme, the second of which is sufficiently long and has a trimmed subject with an ellipsis.

Remaining tasks

User interface changes

Trimmed comment titles appear trimmed.

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because nothing is broken, but this is not a new feature, just a (minor) change in behavior
Issue priority Normal
Unfrozen changes Unfrozen because it only changes markup.
Prioritized changes The main goal of this issue is usability.
Disruption Not disruptive. This changes the makeup of the comment subjects that get saved in the database but it does not change the data structure in any way and the trimming is a one-time operation so this is 100% backwards-compatible not only with contributed modules but also with existing sites.

Comments

tstoeckler’s picture

Issue summary: View changes

Adding issue summary and beta evaluation.

tstoeckler’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Needs usability review
StatusFileSize
new35.76 KB
new857 bytes

Here we go.

Tagging Needs usability review and adding an "after" screenshot to the issue summary. The "before" screenshot is identical but for the ellipsis, so I hope that's sufficient.

Status: Needs review » Needs work

The last submitted patch, 2: 2463579-2-comment-subject-ellipsis.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new853 bytes

Sorry, had an outdated 8.0.x locally.

Status: Needs review » Needs work

The last submitted patch, 4: 2463579-4-comment-subject-ellipsis.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB
new1.91 KB

Fixed the tests.

Shivam Agarwal’s picture

#tstoeckler This patch doesn't apply on my system. Following error is thrown :

Checking patch core/modules/comment/src/CommentForm.php...
warning: core/modules/comment/src/CommentForm.php has type 100755, expected 100644
error: while searching for:
      // 2) Strip out all HTML tags
      // 3) Convert entities back to plain-text.
      $comment_text = $comment->comment_body->processed;
      $comment->setSubject(Unicode::truncate(trim(Html::decodeEntities(strip_tags($comment_text))), 29, TRUE));
      // Edge cases where the comment body is populated only by HTML tags will
      // require a default subject.
      if ($comment->getSubject() == '') {

error: patch failed: core/modules/comment/src/CommentForm.php:301
error: core/modules/comment/src/CommentForm.php: patch does not apply
Checking patch core/modules/comment/src/Tests/CommentInterfaceTest.php...
warning: core/modules/comment/src/Tests/CommentInterfaceTest.php has type 100755, expected 100644
error: while searching for:
    $body_text = 'Lorem ipsum Lorem ipsum Loreming ipsum Lorem ipsum';
    $comment1 = $this->postComment(NULL, $body_text, '', TRUE);
    $this->assertTrue($this->commentExists($comment1), 'Form comment found.');
    $this->assertEqual('Lorem ipsum Lorem ipsum', $comment1->getSubject());

    // Break at 29 characters where there's no boundary before that.
    $body_text2 = 'LoremipsumloremipsumLoremingipsumLoremipsum';
    $comment2 = $this->postComment(NULL, $body_text2, '', TRUE);
    $this->assertEqual('LoremipsumloremipsumLoremingi', $comment2->getSubject());
  }

  /**

error: patch failed: core/modules/comment/src/Tests/CommentInterfaceTest.php:220
error: core/modules/comment/src/Tests/CommentInterfaceTest.php: patch does not apply

Shivam Agarwal’s picture

Status: Needs review » Needs work

I was going through your patch and found that following thing doesn't exist in my files :

 $body_text = 'Lorem ipsum Lorem ipsum Loreming ipsum Lorem ipsum';
-    $this->assertEqual('Lorem ipsum Lorem ipsum', $comment1->getSubject());
     $comment2 = $this->postComment(NULL, $body_text2, '', TRUE);
-    $this->assertEqual('LoremipsumloremipsumLoremingi', $comment2->getSubject());
tstoeckler’s picture

Status: Needs work » Needs review

@Shivam Agarwal: Please make sure you have the latest 8.0.x code. The automated testing infrastructure had no problem applying the patch so it seems there must be some problem with your setup.

Shivam Agarwal’s picture

@tstoeckler, I already have latest code with clean head. I have cross checked it twice. Maybe I am missing with something else. Can you please guide me on it?

mikeker’s picture

The patch in #6 applies cleanly. @Shivam Agarwal: I'm not sure what is causing the errors you're seeing but them seem to be limited to your localhost.

I've tested the patch and verified it works as expected and would move it to RTBC except for the "Needs usability review" tag, which I don't feel qualified to do.

This gets a big +1 from me! Thank you @tstoeckler.

Shivam Agarwal’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new23.05 KB

Yes, patch works! Screenshot attached.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2463579-6-comment-subject-ellipsis.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
Shivam Agarwal’s picture

Status: Needs review » Reviewed & tested by the community

Screenshot attached in #13.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b85ec52 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation.

  • alexpott committed b85ec52 on 8.0.x
    Issue #2463579 by tstoeckler: Add an ellipsis to truncated comment...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.