Comments are not filtered on language

Created on 17 June 2016, over 8 years ago
Updated 23 January 2024, 10 months ago

Problem/Motivation

The situation, I have a Drupal 8 multilingual node where Dutch is the main language and French is the other.
If I add a comment to the Dutch node translation and approve it, it will show. But it will also show in the French translation.
I think it is rather weird to see a mix of Dutch and French below a Dutch node.

P.S. as a quick workaround I created a view which shows me the comments based on the current node and filtered on a language. But it would be better that this approach is not necessary.

Proposed resolution

Add an option to select the language for show the comments.

Remaining tasks

Add test coverage.

User interface changes

A new option is added in the 'Manage display' tab for the comment which allow to config the language filter to show the comments.

API changes

The language_manager service is now injected to the CommentStorage class.

Data model changes

A new configuration named language_filter is now available to store the language configuration for display the comments.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Commentย  โ†’

Last updated about 2 hours ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium yvesvanlaer

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dietric@gmail.com

    dietric@gmail.com โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance urashima82

    Hello, I'm sending a new patch because I was facing an issue when I tried to display comments. Due to a strange behavior of the comment_count property, the comments are not always shown.

    I replace that by an entity query and it works.

    To respond to @bigboy, I was facing the same redirect problem. To solve that, I used the hook_form to add my custom submit method.
    Here is en example, feel free to improved it :

    /**
     * Implements hook_form_alter().
     */
    function my_module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
      $comment_forms = [
        'comment_comment_form',
        'comment_comment_edit_form',
        'comment_comment_delete_form',
      ];
      if (in_array($form_id, $comment_forms)) {
        $form['actions']['submit']['#submit'][] = 'my_module_comment_fix_form_submit';
      }
    }
    
    function my_module_comment_fix_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
      $route_params = \Drupal::routeMatch()->getParameters();
      if ($route_params->has('entity')) {
        $node = \Drupal::routeMatch()->getParameter('entity');
      }
      else {
        // Get the comment entity.
        $comment = \Drupal::routeMatch()->getParameter('comment');
        // Get the node entity.
        $node = $comment->getCommentedEntity();
      }
      // Get translated url.
      $url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $node->id()]);
      $form_state->setRedirectUrl($url);
    }
    
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    Custom Commands Failed
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    Custom Commands Failed
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia anchal_gupta

    I have uploaded the patch.
    Fixed CFF
    Please review

Production build 0.71.5 2024