Updated as of #50
Problem/Motivation
Found in #2006606-46: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations. When an entity (eg. node) is rendered in a language that is different from the page's language, the links are still rendered in the page's language, so the node title, read more link, etc. will lead to the version of the entity in the language of the page instead of the language displayed on the prior page.
With a view displaying different language copies of the same node:
Proposed resolution
Initial proposed solution: The links generated need the language passed on explicitly, so the right language version links are generated.
Now proposed solution: load the right translation of the node at the start, that then passes on the right information for the links code. (See interdiff in #35). still pass the language as it might be used for something else.
This issue is not about fixing the duplicates on the front page view. That would be #2161845: Node views (front page, admin) do not use the proper language filter.
Remaining tasks
- (done) Get read more links pointing to correct language
- (?) Figure out if more affected places exist.
- (done) Write tests.
- Review
- open follow-ups (at least see #66, read other comments also)
User interface changes
Links fixed.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#64 | GREEN-enhanced-test-2149649.patch | 1.52 KB | droplet |
#64 | RED-fail-test.patch | 2.14 KB | droplet |
#64 | GREEN-weak-test.patch | 633 bytes | droplet |
#57 | drupal_2149649_57.patch | 7.35 KB | Sweetchuck |
#50 | drupal_2149649_50-tests-only.patch | 6.36 KB | YesCT |
Comments
Comment #1
Gábor HojtsyUploading patch from @dawehner in #2006606-48: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations.
Comment #2
Gábor HojtsyComment #4
Gábor HojtsyShould have been filed against core :)
Comment #5
Gábor Hojtsy1: 2149649.patch queued for re-testing.
Comment #7
herom CreditAttribution: herom commentedlangcode is
language()->id
. right?Comment #9
herom CreditAttribution: herom commentedComment #10
herom CreditAttribution: herom commentedComment #12
Gábor HojtsyThe language option needs the FULL language object, not just the langcode. We made a concerted effort to name arguments that expect a langcode a 'langcode'/$langcode, so if you see 'language', you can be sure that takes an object :)
Comment #13
plachLet's try again
Comment #15
vijaycs85Updating path alias test to work with this change...
Comment #16
vijaycs85Comment #17
Gábor HojtsyI know @plach was not entirely happy with this approach, but what better could we do? I think its not a big thing to ask to pass on language for the link generation and making the translation entity object somehow pass along may not be practical? Looks good to me.
Comment #18
plachLet's move forward with this for now. If there is a way (and time) to improve things later we will try :)
Comment #19
Gábor HojtsyAll right, looks good to me then. Thanks @plach for the confirmation.
Comment #20
XanoRe-roll because of
EntityInterface::url()
.Comment #21
Gábor HojtsyComment #22
alexpottdrupal_2149649_20.patch no longer applies.
Comment #23
XanoRe-roll.
Comment #24
Gábor HojtsyThanks!
Comment #25
xjm.
Comment #26
vijaycs85Removing 'Needs reroll' as the latest patch apply without any conflict.
Comment #27
YesCT CreditAttribution: YesCT commentedI took a look at the test changes, but I dont see where it is testing to make sure the title (or read more) link goes to the language the node is being shown in.
I tried it out, and it seems to help the title, but not the read more.
A
With head
on front page /af, all links (title and read more) go to /af/node/1
B
With patch
on front page /af, title goes to /af/node/1,
but read more goes to /node/1
which is not what I expected
C
with just #2006606: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations (note I didn't run into the error that was last reported there, sent that issue for retest.)
on front page /af, all links (title and read more) (of the one showing en title and body, and of the one showing af title and body) goes to /af/node/1
which is kind of ok. the question is does this issue fix things once with the case of having that patch applied?
D
with patch and #2006606: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations
on front page /af, it does fix the title link for the english displaying node to go to /node/1, but the read more links are both /af/node/1 (and when front page /, they are both /node/1)
------
So, I think this patch helps, but still needs work to make other links (read more) know the language also, and for tests to test it.
Comment #28
Gábor HojtsyIndeed, the read more link does not seem to be affected based on looking at the patch.
Comment #29
webchickThis is a major regression from 7.x, so bumping.
Comment #30
YesCT CreditAttribution: YesCT commented#2006606: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations was committed, so we can just work on this directly. Right now, the read more links are what we need to get working.
Comment #31
Gábor HojtsyAnybody can help with that? :)
Comment #32
Gábor Hojtsy@YesCT: I looked at this to fix, but seems like both the node title and the read more link are covered in the same way:
This line is supposed to make the read more link point to the right place.
This is supposed to make the title link point to the right place.
Can you still reproduce the read more link pointing at the wrong place with the patch? (#2006606: Views rendering ignores entity language, eg: Identical nodes rendered in views when nodes have translations was committed in the meantime).
Comment #33
Gábor HojtsyBTW here is a reroll since this did not cleanly apply anymore.
Comment #34
Gábor HojtsyAlso when trying this, noticed a
Fatal error: Call to a member function language() on a non-object in /home/s551122e341a9c85/www/core/modules/comment/comment.module on line 468
which is obviously because the comment link has no $entity variable anymore, but a $node.Comment #35
Gábor HojtsyThe node read more links and the comment add links were incorrect indeed. Reason being the node was loaded as-is without regards to the language context. Then the language context was passed on to the links alter but not considered. If we just load the right translation of the node at the start, that then passes on the right information for the links code.
Needs tests since the above passed tests although it should not have, given the read more and the comment links were not good.
Comment #36
Gábor HojtsyProof that this works well :) Now should only need more tests and should be good to go hopefully. Who can help with tests?
Comment #40
Gábor HojtsyUhm, this segfaulted. Not sure how that would be related:
Also don't think there would be things related there. So retesting. BTW the reason for leaving the prior patches to get tested was to see if a simple reroll vs. the fixes would fail at a point. Since those were cancelled, we don't know anymore.
Comment #41
Gábor Hojtsy35: drupal_2149649_35.patch queued for re-testing.
Comment #42
Gábor Hojtsy#35 now passed, so need more tests. Tagging as random fail for #40, the full fail message is there.
Comment #43
YesCT CreditAttribution: YesCT commentedjust the readmore link tested.
copied from NodeAccessBaseTableTest
looked up the preg_match | syntax, but still not sure if it's needed. kept it in the copy and pasted code.
test only patch should fail. (fails locally)
patch should pass (the new tests pass locally)
---
while I was looking into this, I wondered why there is a $node->save(); after the hunk making translations. that is unrelated to this issue, but if it's not needed, would be a good novice issue to deal with it.
---
next, the comment (and remove the @var, which I was experimenting with)
Comment #44
YesCT CreditAttribution: YesCT commentedadding tag back.
Comment #47
YesCT CreditAttribution: YesCT commentedfail from #40 (see #2216701: Random test failure in ToolbarAdminMenuTest), but also
and some similar ones.
retesting though, since the previous patch passed, and this one only changed a test.
Comment #48
YesCT CreditAttribution: YesCT commented43: drupal_2149649_42.patch queued for re-testing.
Comment #49
YesCT CreditAttribution: YesCT commentedI thought of doing this, but the pattern for the default language (en in the test), is also present in the other langcode's hrefs, so it counts more than one.
so, went back to check checking it found at least one of each..
but that makes the check for en silly. (it wont fail if the en is not on the front page)
Comment #50
YesCT CreditAttribution: YesCT commentedah, on retest, #42 passes.
ok. @sun suggested using a[starts-with( in xpath. But since I wanted to check both the link text and the ref, used the xpath to get the matches to the link text and then preg_match to check the ref.
@jhodgdon mentioned that they might have written a function that checks for matches both the text and ref at one point for drupal 7, but I didn't get details of where that might be.
This uses base_path(). And makes sure there are exactly 1 matches.
I dont use the $matches variable that is passed to preg_match(), so maybe that should be taken out.
Also, The two hunks of code could be merged so we loop just once through the languages.
But those are kinda small things.
Putting this out there for people to check if it's even the right place for tests and going in the right direction.
Removing the needs tests tag since this adds tests.
Since people will ask why there are duplicates on the front page anyway, adding the related issues from the parent here as well.
Comment #52
YesCT CreditAttribution: YesCT commentedthe tests only failed as expected.
needs review. (we are very close, so look at everything, solution and tests)
Comment #53
jhodgdonI just added a related issue:
#2217569: Fields row plugin: Translation is non-uniform for base fields, Field UI fields, links; no way to choose "this row's language"
which has to do with field rendering in views (if instead of using "teasers" as the output, you select the "fields" row plugin and display the Body field for instance). Just pointing it out as people on this issue may be interested in the other one too...
Comment #54
Gábor Hojtsy@plach / @vijaycs85 what do you think?
Comment #55
Wim LeersPatch looks sane :)
Comment #56
SweetchuckThe patch #50 cannot be applied to the latest 8.x any more.
I am going to reroll.
Comment #57
SweetchuckReroll patch #50
Comment #58
SweetchuckWithout the patch I experience the same problem as described in the issue summary.
I added 3 different languages (English, Hungarian, Polish)
I enabled the translation support for node:article on page admin/structure/types/manage/article.
And I enabled the translation support for some of the fields of the article on page admin/config/regional/content-language.
I created an Article with English language.
Translate to Hungarian
Translate to Polish, used the English version as source of the translation.
Both of them are promoted to front page. (Issue 2006606)
When I visit the front page the node title is points to the proper link, but the "read more" link is points to the current interface language version of the given node, even if such translation is not exists.
With the patch every "read more" link points to the proper language variants of the given node.
Comment #59
SweetchuckComment #60
jhodgdonThanks Sweetchuck for testing!
So it sounds like the patch now applies and has been manually tested to work.
I looked over the code and tests, and I think the code looks good (all 6 lines or so that changed), and the test changes also make sense.
In #50, there was also a test-only patch, which failed where it was expected to fail (I looked at the test result page, and the test definitely was finding the bug reported on this issue).
Wim in #55 also deemed the patch to be "sane".
The issue summary even reflects the current status of the issue.
So... I think this can be marked RTBC. Great work!
Comment #62
alexpottCommitted 0a8e34c and pushed to 8.x. Thanks!
Comment #63
Gábor HojtsyGreat to see this in :) Thanks all!
Comment #64
droplet CreditAttribution: droplet commentedEnhanced tests to catch Node title link [$node->url()] errors.
Comment #66
alexpott@droplet can you open a new issue to do the enhanced testing - definitely looks like an improvement but it's not as critical as the original work.
Comment #67
droplet CreditAttribution: droplet commented#2234053: [Follow up] Enhanced Entity language tests
Comment #68
sunComment #69
YesCT CreditAttribution: YesCT commentedtagging needs followup per #66
Comment #71
jhodgdonI do not think this was fixed. It seems like the title links are still all going to node/1 not fr/node/1 or whatever. This issue was I think repurposed to only be about links. I'm reopening to see if anyone else agrees that it is not actually fixed.
Comment #72
Gábor Hojtsy@jhodgdon: the scope of this issue was about links in the node entity display. I think you are referring to field links in views not with entity displays? Please reopen if the scope of this issue is not fixed, that is if the title and/or read more links on nodes do not lead to the proper page when displayed as an entity in teaser or full view.
Comment #73
jhodgdonOh sorry, my mistake indeed! I was referring to Views. I'll see if there's an open issue...
Comment #74
Gábor HojtsyNo, well, this IS a views page (front page) but it uses entity rendering NOT field rendering. Is that the combination you have issues with?
Comment #75
jhodgdonThe problem I am seeing is this:
If I make a view of nodes (which is really a view of node translations). I display it using Fields. I put in the Title field, and check the "Link this to the entity".
All of the links go to node/1, not to a translation page.
Comment #76
Gábor HojtsyYeah all the changes and scope of this patch is/was focusing on rendering the node as an entity (node_links hook changes, NodeView.php fixing, etc). Not as fields. I don't think we have an issue for that. Hopefully that should not be too bad, since the field rendering should also get the field language passed (and even use the right translation based on that?). But it should be a different issue. Happy to help there :)
Comment #77
jhodgdonOK, I did a quick test and confirmed that if you use Content/display mode in Views, the links are correct. I think the links being wrong at field level are probably part of #2217569: Fields row plugin: Translation is non-uniform for base fields, Field UI fields, links; no way to choose "this row's language" and I'll make a note there. Thanks for the clarification!