Skip to content
Snippets Groups Projects

#ISSUE 3346218 Add a different message on edit comment

Closed Kaushik Vishwakarma requested to merge issue/drupal-3346218:10.0.x into 10.1.x

adding diffrent message on edit post result of a comment

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
392 393 $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
393 394 }
394 395 }
395 else {
396 elseif ($insert) {
396 397 $this->messenger()->addStatus($this->t('Your comment has been posted.'));
397 398 }
399 else {
400 $this->messenger()->addStatus($this->t('Your comment has been updated.'));
401 }
  • This is looking great, surprised it hasn't been reported before. I just have one observation about code readability.

    Also, this will need to be against 10.1.x because of the string change.

  • added 1 commit

    • 6fd3dc70 - Make getStatusMessage() method to get message but their is cache ,I think...

    Compare with previous version

  • added 1 commit

    • 17684add - I just figure out $this->entity->isNew() return valid response where as...

    Compare with previous version

  • 368 /**
    369 * {@inheritdoc}
    370 */
    371 protected function getStatusMessage($insert,$comment){
    372 if (!$comment->isPublished()) {
    373 if (!$this->currentUser->hasPermission('administer comments')) {
    374 return $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
    375 }
    376 }
    377 if ($insert) {
    378 return $this->messenger()->addStatus($this->t('Your comment has been posted.'));
    379 }
    380 else {
    381 return $this->messenger()->addStatus($this->t('Your comment has been updated.'));
    382 }
    383 }
    • Comment on lines +371 to +383

      Some suggested improvements:

      • Adding typehints
      • Removing else, which is the point of the method, to simplify the code
      • Return a message rather than setting it on the messenger, leave that to the calling code
      Suggested change
      372 protected function getStatusMessage($insert,$comment){
      373 if (!$comment->isPublished()) {
      374 if (!$this->currentUser->hasPermission('administer comments')) {
      375 return $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
      376 }
      377 }
      378 if ($insert) {
      379 return $this->messenger()->addStatus($this->t('Your comment has been posted.'));
      380 }
      381 else {
      382 return $this->messenger()->addStatus($this->t('Your comment has been updated.'));
      383 }
      384 }
      372 protected function getStatusMessage(bool $insert, CommentInterface $comment): TranslatableMarkup {
      373 if (!$comment->isPublished()) {
      374 if (!$this->currentUser->hasPermission('administer comments')) {
      375 return $this->t('Your comment has been queued for review by site administrators and will be published after approval.');
      376 }
      377 return $this->t('The comment draft was updated.');
      378 }
      379 if ($insert) {
      380 return $this->t('Your comment has been posted.');
      381 }
      382 return $this->t('Your comment has been updated.');
      383 }
      Edited by Lee Rowlands
    • Please register or sign in to reply
  • 386 402 'link' => Link::fromTextAndUrl(t('View'), $comment->toUrl()->setOption('fragment', 'comment-' . $comment->id()))->toString(),
    387 403 ]);
    388 404
    389 // Explain the approval queue if necessary.
    390 if (!$comment->isPublished()) {
    391 if (!$this->currentUser->hasPermission('administer comments')) {
    392 $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
    393 }
    394 }
    395 else {
    396 $this->messenger()->addStatus($this->t('Your comment has been posted.'));
    397 }
    405 $this->getStatusMessage($insert,$comment);
  • Looking good, a couple of suggestions

  • added 1 commit

    • 99f36a10 - refactor code of getStatusMessage

    Compare with previous version

  • adding :`TranslatableMarkup at getStatusMessage is not working showing unexpected error caught on submiting form .This changes working for me

  • added 1 commit

    • 9ca0c9a0 - Corrected Custome command Failed error

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 366 366 $form_state->setRebuild();
    367 367 }
    368 368
    369 /**
    370 * {@inheritdoc}
    371 */
    372 protected function getStatusMessage(bool $insert, CommentInterface $comment) {
  • added 1 commit

    Compare with previous version

  • Kaushik Vishwakarma added 117 commits

    added 117 commits

    • 0b459903...f4fc5940 - 105 commits from branch project:10.0.x
    • f4fc5940...6e6fa822 - 2 earlier commits
    • 0f0d686c - changes test case
    • 776dc1e1 - change test in commentPreviewTest
    • 9388e209 - Use "Your comment has been posted." message for new comments
    • 71ff8da2 - Revert testUserDelete
    • fc3068f0 - Make getStatusMessage() method to get message but their is cache ,I think...
    • 73eb3e38 - I just figure out $this->entity->isNew() return valid response where as...
    • 67649847 - refactor code of getStatusMessage
    • 8b129d46 - Corrected Custome command Failed error
    • ac85519d - CCF corrected
    • f3dc82dd - added TranslatableMarkup

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading