Comments are not filtered on language

Created on 17 June 2016, almost 9 years ago
Updated 31 May 2023, about 2 years 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 2 days 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 over 1 year ago
    Custom Commands Failed
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Custom Commands Failed
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia anchal_gupta

    I have uploaded the patch.
    Fixed CFF
    Please review

  • Status changed to Needs review about 1 month ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain pcambra Asturies
  • The Needs Review Queue Bot โ†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request โ†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance erwangel

    Thanks to cptX (#58), I have no more "page not found" errors. My site is multilingual but comments translation is not enabled. It was a disaster for SEO as every permalink was giving a "page not found" when not in the default interface language. I don't see a solution for this in the last patch (#62).

Production build 0.71.5 2024