Problem/Motivation

The comments attached to the entity has the attributes 'status' which controls whether comments can be seen/posted. But seems like no possibility to show that status in the views and not possibility to filter on that status.
P.S. It's very strange that I cannot find the issue related to this. Maybe I'm missing something.

Testing steps

  1. Apply the patch.
  2. Clear cache.
  3. Add/Edit the comment field of node.
  4. On Node Manage Display for the Comment field a new formatter should be available in the select list ("Comment Status").
  5. On selecting and saving the settings, this should show the comment status for each of the comment.

Proposed resolution

Seems like the filter plugin is already created but is not used anywhere. I propose to create field plugin which displays that status and add both plugins (field and filter) to field_views_data.

Seems like InOperator plugin feels very bad when options are instances of TranslatableMarkup. So for now I'm casting options to string. Maybe in the future it will be possible to find better solution.

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

mpolishchuck created an issue. See original summary.

mpolishchuck’s picture

Adding the patch.

mpolishchuck’s picture

Status: Active » Needs review

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev

Not sure if this should be considered for core, but patch applies cleanly to 9.1.x.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

harlor’s picture

Well #2 breaks the current behavior of the comment field. Instead of the list of comments one only gets the comment status in views.

Can't we just add a field formatter as an alternative to CommentDefaultFormatter to show the comment status?

harlor’s picture

StatusFileSize
new1.45 KB

Sorry I just uploaded an incorrect patch.

kristen pol’s picture

Issue tags: +Needs manual testing

Tagging for testing.

kristen pol’s picture

I reviewed the code and it looks very clean :)

joshua1234511’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing
StatusFileSize
new1.48 KB
new20.86 KB

Thank you @harlor, On reviewing the code found the below issue.

diff --git a/modules/comment/src/Plugin/Field/FieldFormatter/CommentStatusFormatter.php b/modules/comment/src/Plugin/Field/FieldFormatter/CommentStatusFormatter.php
...
+++ b/modules/comment/src/Plugin/Field/FieldFormatter/CommentStatusFormatter.php

Patch being applied at incorrect location.
Should be a/core/modules/comment/src/....

Updated the patch to apply at correct path location.

Manually tested the patch, works as expected.

kristen pol’s picture

Status: Reviewed & tested by the community » Needs review

Thanks @joshua1234511 for updating the patch. If someone uploads a patch, then they aren't supposed to RTBC the patch so I'm moving back to needs review so we can get other eyes. I might be able to review today.

kristen pol’s picture

To review the code more carefully, I wanted to see how status is handle in views for other things and here's some things I found:

  1. core/modules/file/src/Plugin/views/filter/Status.php: class Status extends InOperator
      public function getValueOptions() {
        if (!isset($this->valueOptions)) {
          $this->valueOptions = [
            0 => $this->t('Temporary'),
            FileInterface::STATUS_PERMANENT => $this->t('Permanent'),
          ];
        }
        return $this->valueOptions;
      }
    
  2. core/modules/media/src/Plugin/views/filter/Status.php: class Status extends FilterPluginBase
  3. core/modules/node/src/NodeViewsData.php: class NodeViewsData extends EntityViewsData
    public function getViewsData() {
    ...
        $data['node_field_data']['status']['filter']['label'] = $this->t('Published status');
        $data['node_field_data']['status']['filter']['type'] = 'yes-no';
        // Use status = 1 instead of status <> 0 in WHERE statement.
        $data['node_field_data']['status']['filter']['use_equal'] = TRUE;
    ...
    
  4. core/modules/node/src/Plugin/views/filter/Status.php: class Status extends FilterPluginBase
  5. core/modules/user/src/UserViewsData.php: class UserViewsData extends EntityViewsData
    public function getViewsData() {
    ...
        $data['users_field_data']['status']['filter']['label'] = $this->t('Active');
        $data['users_field_data']['status']['filter']['type'] = 'yes-no';
    ...
    

In the comment module currently, there are these filters: NodeComment, StatisticsLastUpdated, and UserUid where NodeComment is currently dealing with status:

/**
 * Filter based on comment node status.
 * 
 * @ingroup views_filter_handlers
 * 
 * @ViewsFilter("node_comment")
 */
class NodeComment extends InOperator {
  
  public function getValueOptions() {
    $this->valueOptions = [
      CommentItemInterface::HIDDEN => $this->t('Hidden'),
      CommentItemInterface::CLOSED => $this->t('Closed'), 
      CommentItemInterface::OPEN => $this->t('Open'),
    ];
    return $this->valueOptions;
  }   
    
}

The patch adds a FieldFormatter (CommentStatusFormatter). I don't see a similar pattern for the File, Media, or Node entities, so I'm not clear this approach would be accepted into core.

kristen pol’s picture

@joshua1234511 Would you please update the issue summary with steps to test this?

joshua1234511’s picture

Issue summary: View changes

I updated the issue summary with testing instructions.

joshua1234511’s picture

@mpolishchuck thinking of the use case, the patch provided adds a new field formatter, that only displays the status and not all details. As far as views are concerned a status field can be easily added to views and the filters can be obtained. the default views show only enabled comments and un approved comments are shown in another tab view.
as the status will be available only for admin, don't see its use for regular users.
and comments are already filters in
.../admin/content/comment
.../admin/content/comment/approval

kristen pol’s picture

Thanks for the clarification @joshua1234511. Since the title and issue summary mentions views, I assumed that the patch would be updating the views filter or field.

Tagging for updating the issue summary to clarify what this new feature really should be.

kristen pol’s picture

Issue summary: View changes

Moved the testing steps higher up on issue summary so they are easier to find.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

deepalij’s picture

Assigned: Unassigned » deepalij
anchal_gupta’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new300.11 KB
new107.21 KB

I have applied Patch #14, it was successfully applied and working fine.

deepalij’s picture

Assigned: deepalij » Unassigned
Status: Reviewed & tested by the community » Needs work
StatusFileSize
new102.86 KB
new148.84 KB
new33.83 KB
new726.33 KB
new742.31 KB
new6.48 MB

Successfully applied the patch #14.

Testing Steps followed:
1. Applied the patch
2. Cleared cache
3. Go to /admin/structure/types/manage/article/display
4. Ensure the Comment field options -> Select "comment status" -> Save
5. Now, create content of type Article (for checking the comment status) by visiting /node/add/article
6. Fill up mandatory fields -> Save
7. Observe the error message
8. Go to the Recent log messages and check the error

Expected Result:
Selecting and saving the settings should show the comment status for each comment

Actual Result:
Comment status is available in the manage field
But, to check the comment status on comments when trying to create a node, it's giving the 500 error message as shown in the attached video and in the screenshots

Hence, moving to needs work.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bobooon’s picture

Status: Needs work » Needs review

+1 RTBC for #14 on Drupal 9.5.x. Previously reported errors appear to be related to using the new Olivero theme. Not this patch.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Was tagged in issue summary in #20 which still needs to happen.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.