Problem/Motivation
In a multilingual site if you add a comment on a node which is in the default language, everything is okay.
But if you add a comment on a node which is not in the default language, I get redirected to the default language translation of the node.
This is very confusing for the end user and they should stay in the same node language after submitting a comment.
Steps to reproduce the issue
This is very easy to replicate on simplytest.me (choose multilingual setup).
If simplytest.me is down (as it currently appears to be), use the following:
$ composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction
- install Drupal (for example, use
drush si
to install Drupal in Italian):
$ drush si standard \ --db-url='mysql://root@127.0.0.1/some_dir' \ --account-name="Kay V" --account-pass=silly.walk.ministry \ --site-name=Some-Dir \ --site-mail=noreply@example.com \ --locale=it
- add other languages (e.g. Chinese (simplified), French & English) via UI at
admin/config/regional/language
- otherwise leave defaults (e.g. skip enabling language switching block; leave Detection and selection method as Url; leave language prefixes unchanged)
- add an article in the default language (by default the article content type includes all entity requirements involved in this bug report)
/node/add/article
- add a comment to the article and hit save
- note whether a language prefix appears in the url (no prefix should be there, as this is the default language)
- create a new article in another language by entering a different prefix in the url e.g.
/en/node/add/article
- add a comment to the article and hit save
- note again whether a language prefix appears in the url (if the issue exists, the prefix will be missing)
- apply patch
- drop db tables
- repeat from step 2 above
Proposed resolution
Redirect the user to the node translation where the comment is made.
Remaining tasks
Manual testing
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#113 | drupal-3019701-113-submit-comment-multi-lang-redirect.patch | 4.99 KB | wuinfo - Bill Wu |
#106 | 2751269-106.patch | 4.79 KB | Spokje |
| |||
#106 | interdiff_101-106.txt | 9.1 KB | Spokje |
Issue fork drupal-2751269
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
ogggg CreditAttribution: ogggg commentedI can confirm this bug.
Comment #7
adriancidI can confirm this bug too.
Adding the Issue Template to the description.
Comment #8
adriancidComment #9
kay_v CreditAttribution: kay_v as a volunteer commentedComment #10
kay_v CreditAttribution: kay_v as a volunteer commentedComment #11
kay_v CreditAttribution: kay_v as a volunteer commentedComment #12
kay_v CreditAttribution: kay_v as a volunteer commentedI was able to confirm the bug.
I'm marking this issue as 'needs work' with the caveat that the patch may be playing the role it needs to play. Pretty complex matrix of possibilities. Of course it is - it’s multilingual.
Unfortunately (and admittedly with no expert insights into how all the contributing chunks need to link up) I’m not getting the expected results when I save a comment with the patch applied. After the patch, the url to which users are redirected on saving a comment does not contain the language code (uncertain if in fact it should, but I believe it should). The interface has an unexpected mix of languages, perhaps indicating that the patch is working in part. If I enter the language code in the url, I see the unadulterated interface language I anticipate.
My steps to reproduce the issue are in the issue summary; the steps include a lot of detail in case variation is needed to ensure consistency of outcome. It’s certainly worth reviewing my steps in case something there is affecting the context of the patch.
Patch applies cleanly.
Errors appear in Watchdog, esp.
| locale | 04/05/2018 - 22:30 | Created JavaScript translation file for the language… | Kay V |
| page not found | 04/05/2018 - 22:30 | /fr/node/3 | Kay V |
| page not found | 04/05/2018 - 22:30 | /en/node/2 | Kay V |
| locale | 04/05/2018 - 22:30 | Updated JavaScript translation file for the language… | Kay V |
| comment | 04/05/2018 - 22:30 | Comment posted: suppongo che il prossimo…. | Kay V | Visualizza |
Notes on what wouldn't be possible to know from the watchdog lines above:
Comment #13
kay_v CreditAttribution: kay_v as a volunteer commentedComment #14
alexseif CreditAttribution: alexseif commentedI'm also affected by this.
More over, I can't even get the comments to display in the language they were submitted in
https://drupal.stackexchange.com/questions/257610/multilingual-comments-...
Comment #15
adriancid@alexseif, there are 2 others patches that you need to apply to get the comments fully functional when you have a multilingual site.
#2751267-16: Comments are not filtered on language
#2958935-9: Comments created in translation are displayed only for admin role
Comment #16
kay_v CreditAttribution: kay_v as a volunteer commentedDoes this issue (and related issues) possibly merit a higher level of urgency ("major" vs "normal")? It appears, from my brief glimpse at its scope while testing the proposed patch, that the effect on commenters is substantial, and the system affected (the comment system) is a fundamental part of Drupal core. Just floating the notion.
Comment #17
adriancid@kay_v yes there are many problems with the comments and the multilingual.
Comment #18
andypostAll related issues needs work still, in multilingual env looks filtering is best solution in long run
it should be entity repository service, so it needs injection
Comment #20
cosolom CreditAttribution: cosolom commentedIf i don't have content in current language (node opened in fallback language mode), then after submit comment i still redirecting to default node language. To prevent this behavior i used this patch
Comment #21
ergonlogicComment #22
ergonlogicI'm also seeing this behaviour when deleting comments. That is, if I delete a French comment, I'm redirected to the English (default) page.
The patch in #20 works nicely when creating new comments, though.
Comment #23
ergonlogicHere's a patch that uses the same approach as #20, to fix redirects following deleting a comment too.
Comment #24
nanakPatch ported for 8.7.x., where urlInfo() became toUrl(), preventing #23 from applying.
Comment #27
kkalashnikov CreditAttribution: kkalashnikov commentedComment #28
kkalashnikov CreditAttribution: kkalashnikov commentedComment #29
kkalashnikov CreditAttribution: kkalashnikov commentedComment #30
kkalashnikov CreditAttribution: kkalashnikov commentedComment #32
kkalashnikov CreditAttribution: kkalashnikov commentedComment #33
KapilV CreditAttribution: KapilV as a volunteer and at OpenSense Labs commentedHelping patch #23 it's good to solve the above problem.
@ergonlogic thanks.
Comment #34
kkalashnikov CreditAttribution: kkalashnikov at Srijan | A Material+ Company commentedremove deprecated function.
Comment #35
kkalashnikov CreditAttribution: kkalashnikov commentedComment #36
matsbla CreditAttribution: matsbla at Globalbility commented#34 works great!
Comment #37
andypostAs bug it requires test
Comment #38
kkalashnikov CreditAttribution: kkalashnikov commentedComment #39
atul4drupal CreditAttribution: atul4drupal commentedExecuted the patch #34 against Drupal 8.9.x-dev
https://dispatcher.drupalci.org/job/drupal_patches/44839/
Comment #40
atul4drupal CreditAttribution: atul4drupal commentedThe patch at #34 worked for me on 8.9.x
Comment #41
atul4drupal CreditAttribution: atul4drupal at Srijan | A Material+ Company commentedpatch at #34 worked as expected.
On adding comment in non default language it does not redirects to default language as expected and while adding comment in default language system remains in default language.
Tested on 8.9.x-dev, with English(en) as default language and Hindi(hi) being non-default language.
Moving to RTBC.
Comment #42
kkalashnikov CreditAttribution: kkalashnikov at Srijan | A Material+ Company for Drupal India Association commented#DrupalIndiaAssociation
Comment #43
alexpottThis looks an important fix for multi-lingual sites.
Thanks for filing this bug report and for fixing the issue. Bug fixing is very valuable. In order to commit a bug fix, we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:
I've checked the comment tests and it appears that there is not a test of commenting on a translated entity. Adding a test that does that seems essential to proving we've fixed this issue.
Comment #44
rahul.shindeCreating tests.
Comment #45
rahul.shindeAdded test for content and its translated counterpart.
Comment #46
andypostNice! Please file separately test-only.patch to prove it catch regression
Comment #47
alexpottThanks for writing the test @rahul.shinde - it's great to see multilingual comments tested.
Could be something like...
protected
For D9 this needs to have void return type hint.
I don't think that adding methods that is only called once from setUp() is needed here. They're not that long and adds the amount you need to think about when reviewing the test.
Posts a comment on a given node.
First line of function docs need to start with a verb that ends in an s... there are some exceptions see https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...
There's not need for these to be machine names. Something like \Drupal\Component\Utility\Random::sentences() is more appropriate.
Let's assert the path outside of this method. After calling it. Then we don't need to do all of this work and what the test is testing is easier discern by reading it.
I don't think this dynamic-ness is necessary. We only exercise one of these code paths in the test.
Let's assert a 200 response here.
Why do we need the reload entity functionality? I'm not sure this is needed.
Comment #48
rahul.shindeUpdated test, added test-only patch.
Comment #50
alexpottAfter adding the languages we need to call
$this->resetAll();
so the container is in multilingual mode.Here we should pass in $langcode and rewrite this to use the routing system. Less hardcoding of urls and constructing prefixes. So it can be something like
Rather than creating $subject and $comment variables - let's do something like:
$edit['subject[0][value]'] = $this->randomString();
Also not not using (4) because the shorter the string the potential more work to do.
Let's call this $node. And then we can do something like...
We don't need to assign $marathi_node or $french_node here. See above...
We the updated signature this would be something like:
The
$this->assertSession()->addressEquals('mr/node/1#comment-2');
looks really nice now. It's easy to determine what is being tested.Comment #51
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedOn it
Comment #52
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@alexpott i please review this patch the changes has been done as suggested by you in #50.
RE #50.1:Done
RE #50.2:Done
RE #50.3:Done
RE #50.4:Done
RE #50.5:Done
RE #50.6:Done
Comment #53
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedFix lint issue
Comment #54
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedComment #55
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedWorking on it need to create new patch failed to apply on 8.9
Comment #56
alexpott@pavnish thanks for working on this. It's a really good idea if you are submitting a patch that adds a new test (or changes a test) to run the test locally before you upload the patch to drupal.org.
Reviewing #51...
Can be {@inheritdoc}
The :void here makes this only for D9.
Need to document the $langcode parameter.
This is not needed.
Unexpected colon.
We can set the comment without $comment too.
Should pass the 'en' langcode too.
Comment #57
alexpottThe test passes without this change. I'm not sure that this is necessary. Or maybe it is but we've not tested it.
We should add test coverage of deleting one of the comments we've added to. And ensure we end up on the correct url.
Need to add
use Drupal\Core\Url;
to the use statements.Comment #58
rahul.shinde@alexpott, I am uploading following addressing comment #50,
Thank you @alexpott being patient with reviewing changes and suggestions.
Comment #59
alexpott#57 still needs addressing.
{@inheritdoc}
No empty line between the @param's
There's no need to get the translation here. And we can hardcode the langcode passed into postCommentOnMultilingualContent
Comment #60
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedWorking on #59
Comment #61
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@alexpott, I am uploading following addressing comment #59, #57 still need to work looking on test case
RE #59.1:Done
RE #59.2:Done
RE #59.3:Done
interdiff_58_61.txt
submmiting_comment_redirection_issue-2751269-61.patch
test-only.patch
Thank you @alexpott
Comment #62
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedComment #64
rahul.shindeThis will fail as the path is wrong. It should be 'fr/node/1#comment-3'
Comment #65
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@rahul.shinde thanks Please review new patch.It's due to the last change was not saved in my system so the patch was failed.
I was checked in my local by phpunit e.i working fine.i think CTRL+Z applied my mistake at the patch creation time.
@alexpott, I am uploading following addressing comment #59, #57 still need to work looking on test case
RE #59.1:Done
RE #59.2:Done
RE #59.3:Done
interdiff_58_65.txt
submmiting_comment_redirection_issue-2751269-65.patch
test-only.patch
Thank you @alexpott
Comment #67
larowlanThanks for working on this, couple of questions/nits
Do we need this - I'm not sure we do - looking at the code in ->toUrl it is language aware already.
see this hunk in Entity::toUrl()
If we do, then we should inject the language manager, as CommentForm already uses container injection.
Is there a reason we don't use ->getTranslationFromContext here so the two are consistent?
It would require injecting the entity repository, but this class already has container injection from its parent classes.
We'd not need the language manager if we used the entity-repository approach.
ubernit: should be 'an' Article content type (I realise English may be your second language, so apologies for nitpick)
ubernit: two . here
ubernit, we can store $this->assertSession() in a local variable here to avoid creating three instances
Comment #68
larowlanComment #69
alexpottThe big issue that needs to be resolved here is
So while the change makes sense its currently resulting in a much worse user-experience because you're being taken to a page without the comment you've just made!!!!
Comment #70
amjad1233Based on the above reviews and running phpcs on various files.
Comment #71
amjad1233a few more fixes from the previous patch.
Comment #72
andypostI'm not sure it doable yet without solving other issues like
- #2301465: Make comment threading per entity translation
- #2751267: Comments are not filtered on language
- #2990248: Make Comment Admin Overview query alterable
Comment #73
matsbla CreditAttribution: matsbla at Globalbility commentedComment #74
jungleSee \Drupal\Core\Entity\EntityInterface::toUrl()
canonical
is the default. So unnecessary changes.{@inheritdoc}
, lowercaseTests that ... . start with
Tests
{@inheritdoc} or unexpected change.
Or unexpected change, but it's ok.
Comment #75
jungleA lot of unexpected changes here, for coding standards violations, we do not have to get all passed, just get which enabled rules/sniffs passed. I would suggest reverting all unexpected changes to coding standard violations. leave them to coding standards relevant issues.
One way to check coding standard violations against ENABLED rules/sniffs
Checkout the
composer.json
for more:Comment #76
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedWorking On it
Comment #77
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@jungle Hi could you please review this patch all the suggestion in #74 has been implemented.
Thanks
Pavnish
Comment #78
jungleThanks, @pavnish!
Reverting all unnecessary coding standard changes. Changing the target version to 9.1.x.
Continue working on it next.
Comment #79
jungleSee #67.5
Two
;
Good with this kind of changes. as
$this->comment->langcode
,$comment->comment_body->value
are accessing protected properties. maybe we need a follow up to clear up other occurrences cross the core.Comment #80
jungleTagging "Needs followup" for #79.4. Addressing #79.1,2 and 3.
Comment #81
jungleOne line is enough here. Especially
@throws
here makes no sense.Suggestion:
Comment #82
quietone CreditAttribution: quietone as a volunteer commentedI read through the issue checking that all the work is complete. I found these are still to do:
#67.4
#79.4
#81
The last manual test was done in #22 on the patch in #20. There has a been a change to CommentForm.php since then so this needs manual testing.
And one question from a brief look at the patch.
this looks like it is out of scope.
Comment #83
raman.b CreditAttribution: raman.b at OpenSense Labs commentedAddressing pointers from #82
Comment #85
raman.b CreditAttribution: raman.b at OpenSense Labs commentedUnrelated test failure
Comment #87
Ruchi Joshi CreditAttribution: Ruchi Joshi at Srijan | A Material+ Company for Drupal India Association commentedPatch#83 is working as expected-" if I add a comment on a node which is not in the default language, I get redirected to the same translation of the node." Tested it on Drupal 9 version. +1 for RTBC.
Screenshots are attached.
Steps:
1. Visit /admin/modules
2. Install "Language","Configuration Translation","Content Translation"," Interface Translation"
3. Visit /admin/config/regional/language
4. Add "French" language
5. Visit /admin/config/regional/content-language
4. Select Comment and Content from Custom language settings
5. Then Select "TRANSLATABLE" checkbox given against Comment type, Content type- Article and Basic page
6. Mark tick against the checkbox "Show language selector on create and edit pages" Comment type, Content type- Article and Basic page.
7. Save the settings.
8. Create an Article page in default language(English) and then create a french translation for same page.
9. Post comment with French language selection on the french translated page.
10. You will notice the link generated on the posting of comment, url will have "fr" code on it.
11. Now if a comment is posted with Default language(English) selection on french translated page.
12. You will notice the comment link will appear with no code on it.
Comment #88
amjad1233Applied the patch and seems to be working as expected. Just added some ubernit stuff as per interdiff. Moving to RTBC.
Comment #89
alexpott#69 is still not addressed... repeating the comment because it is important.
The big issue that needs to be resolved here is
So while the change makes sense its currently resulting in a much worse user-experience because you're being taken to a page without the comment you've just made!!!!
Also there's #72 from @andypost who is a maintainer of the comment module.
Comment #90
cptX CreditAttribution: cptX commentedCan somebody please give a responsible answer to the following question:
If I make a patch to the kernel to address the above issues and build a production website, if in the future the core is corrected and fixes the above will I be able to update the core and remove the patch, or the comments that will have been created with the applied patch will not be compatible with a future corrected core?
I'm building a new multilingual D9 site the last weeks and I selected Drupal over wordpress because I considered Drupal more mature regarding multilingual capabilities, but the moment I realized the problem with the comments all my plan collapsed and now I don't know what to do. The above problems are critical and I don't want to patch the core.
Can we address the redirect issues in a custom module? What do you suggest to do in order to continue building the site on D9 and to not surrender to wordpress?
In the patch I see changes in the following files:
/core/modules/comment/src/CommentForm.php ->patched
/core/modules/comment/tests/src/Functional/CommentLanguageTest.php ->patched
/core/modules/comment/tests/src/Functional/CommentOnMultilingualContentTest.php -> new created
Can somebody explain what do I have to do in order to correct the issues in a production site? Do I need to patch only the first file or the other two files are also needed for a functional website? The last 2 files are created just for testing?
UPDATE: I applied the patch only in the first file and it works for submit. Preview of the comment in the translated page doesn't work though. Brings a white page. Delete a comment on a tranlated page redirects to the non-translated page. So 2 out of 3 major issues are not yet solved. By viewing all the above posts I don't understand why we spent so much effort in the testing files and not in the real issues which are the following:
1. Redirect after save (patch looks working)
2. Loading preview (no solution at the moment -> white screen of death)
3. Redirect after delete (no solution at the moment -> still redirects to the non translated page)
We are in post #90 and only the first issue is resolved and this thread is 4 years old!!! I consider the issue major and I really am surprised why this hasn't been solved in the core already! This is basic functionality if you want to have a multilingual site. Am I missing something? How are all the rest working on these issues? Is it because D7 was working fine in all these and D8/D9 changed the architecture and produced new issues?
Comment #91
cptX CreditAttribution: cptX commentedCreated a new topic here to raise general awareness for all these issues the comment module has https://www.drupal.org/project/drupal/issues/3196886
Comment #92
andypostComment #93
cptX CreditAttribution: cptX commentedSo as it is the usual case with Drupal, an issue takes years to get solved I decided to solve the issues myself in order to proceed with my project. Here are the modifications I did. I'm not a professional Drupal programmer so I'll place here the code without any code standards. A more qualified person should then review my suggestions and provide them in the form of patches. My modifications presented here address the following issues in version 9.1.2 of Drupal:
For the first issue (save) in file /core/modules/comment/src/CommentForm.php in function "save"
For the second issue (delete) in file /core/modules/comment/src/Form/DeleteForm.php in function "getCancelUrl"
For the third issue (preview) in file /core/modules/comment/comment.module in function "comment_preview"
Please, let's test the above and produce the corresponding patches, and let's hope it will not take 4.5years more...
Comment #94
KevinVb CreditAttribution: KevinVb at Dropsolid commentedUpdated the patch from #83 to make it compatible with Drupal core version 9.1.4
Comment #95
KevinVb CreditAttribution: KevinVb at Dropsolid commentedWell, fixed the file locations in my patch from previous comment.
Comment #96
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at QED42 commentedChanging to needs review for test bot run.
Comment #98
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at QED42 commentedIt seems tests are silently failing and working fine on local.
As drupal's test bot runs test cases inside a subdirectory, this might be causing issues in similar assertions.
I've updated the patch and using Url::fromRoute to create the URLs.
Let's see how it goes.
Comment #100
andypostComment #101
Wilfred Waltman CreditAttribution: Wilfred Waltman as a volunteer commentedRerolled #98 for Drupal 9.2.2
Just changed row number and added an 's' twice.
Comment #102
iadiaz CreditAttribution: iadiaz commentedGreat it worked for me in version 8.9.7
Comment #103
BerdirThis doesn't seem to make any relevant change?
Order argument is incorrectly changed on assertEquals() due to the merge ,and the only other chnage is $node->langcode to $node->get('langcode'). I prefer get() too but functionally it is identical.
Lets try without these changes, I don't see why it wouldn't pass?
$lang is an uncommon variable name, we usually use langcode. I would skip the loop and just call createFromLangcode() twice.
I wouldn't add the @throws on these methods. If you start with that then you'd need to add a lot more from the assertions to be complete. We don't do that on test methods usually.
Hm. So what is the expected behavior if you comment with a language that does _not_ have an active translation?
I would argue that we should actually set the language explicitly even if a translation doesn't exist for it?
For the test, I would then explicitly _not_ add a fr translation and still test it like that.
Comment #104
vikashsoni CreditAttribution: vikashsoni as a volunteer and at Zyxware Technologies commentedpatch not applied in drupal-9.3.x-dev
Needs to re-roll
Comment #105
bnjmnmRemoving credit for #104, a screenshot of a patch not applying does not move the issue forward.
The testbot in #101 is able to apply the patch so clearly it's working.
The screenshot does show that the patch you're attempting to apply is not the most recent - it's trying to apply #88 and it's been rerolled since then - the most recent is #101. You should only apply the most recent patch when reviewing, it is not cumulative. The use of bold is because I've mentioned this on several other issues and you may have missed it.
Comment #106
SpokjeAddressed #103:
1. Changes reverted
2. Done
3. Removed all
@throws \Behat\Mink\Exception\ExpectationException
4. I hope I understood this correctly
Comment #107
SpokjeComment #110
bigboy CreditAttribution: bigboy as a volunteer commentedHad some problems with this issue as well. Don't want to duplicate my comment, so I'll just leave a link here - https://www.drupal.org/project/drupal/issues/2751267#comment-14810709
Comment #111
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Did not read all the comments yet.
But see there are few items in the remaining tasks to be addressed.
Also was tagged for a follow up was that done?
Can re-review later once those are updated
Thanks.
Comment #113
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedThe patch fixes the issue of the page returning to the default language page after submitting a comment in the non-default language comment form. It did not resolve other problems related to previewing comments and deleting comments. The patch is for Drupal development branch 10.2.x.
Comment #114
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe 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.)
Comment #116
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu commentedComment #117
smustgrave CreditAttribution: smustgrave at Mobomo commentedThanks for picking up
MR should be pointed at 11.x branch
Appears to have some remaining tasks that need to be addressed or answered.